Hi all
This is very frustrating. As far as I can tell my code should work.
Indeed, I have got something similar working using VBA (and the
CDO.Message object).
I get the error "The operation has timed out" so I think that it's not
connecting to the SMTP server at all. Anyone got ideas? Here's the
code:
<code>
MailMessage m = new MailMessage();
SmtpClient c = new SmtpClient();
c.DeliveryMetho d = SmtpDeliveryMet hod.Network;
// I've tried this with and without the domain
System.Net.Netw orkCredential cred = new
System.Net.Netw orkCredential(" SmtpUserName", "SmtpPassword") ;
c.EnableSsl = true;
c.UseDefaultCre dentials = false;
c.Host = "SmtpServer ";
c.Port = 465;
c.Credentials = cred;
m.To.Add(new MailAddress("so meone@mail.com" );
m.From = new MailAddress("fr om@mail.com");
m.Subject = "DotNet email";
m.Body = "Hi Ben" + Environment.New Line + "This email
was sent via code through SMTP";
c.Send(m);
</code>
I can't see anything wrong with that. If anyone wants me to post the
VBA code that does work, I will.
I'm thinking that I may have to use CDO, which I don't really want to
do.
Thanks,
Ben
This is very frustrating. As far as I can tell my code should work.
Indeed, I have got something similar working using VBA (and the
CDO.Message object).
I get the error "The operation has timed out" so I think that it's not
connecting to the SMTP server at all. Anyone got ideas? Here's the
code:
<code>
MailMessage m = new MailMessage();
SmtpClient c = new SmtpClient();
c.DeliveryMetho d = SmtpDeliveryMet hod.Network;
// I've tried this with and without the domain
System.Net.Netw orkCredential cred = new
System.Net.Netw orkCredential(" SmtpUserName", "SmtpPassword") ;
c.EnableSsl = true;
c.UseDefaultCre dentials = false;
c.Host = "SmtpServer ";
c.Port = 465;
c.Credentials = cred;
m.To.Add(new MailAddress("so meone@mail.com" );
m.From = new MailAddress("fr om@mail.com");
m.Subject = "DotNet email";
m.Body = "Hi Ben" + Environment.New Line + "This email
was sent via code through SMTP";
c.Send(m);
</code>
I can't see anything wrong with that. If anyone wants me to post the
VBA code that does work, I will.
I'm thinking that I may have to use CDO, which I don't really want to
do.
Thanks,
Ben
Comment