I
iambenb
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.DeliveryMethod = SmtpDeliveryMethod.Network;
// I've tried this with and without the domain
System.Net.NetworkCredential cred = new
System.Net.NetworkCredential("SmtpUserName", "SmtpPassword");
c.EnableSsl = true;
c.UseDefaultCredentials = false;
c.Host = "SmtpServer";
c.Port = 465;
c.Credentials = cred;
m.To.Add(new MailAddress("(e-mail address removed)");
m.From = new MailAddress("(e-mail address removed)");
m.Subject = "DotNet email";
m.Body = "Hi Ben" + Environment.NewLine + "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.DeliveryMethod = SmtpDeliveryMethod.Network;
// I've tried this with and without the domain
System.Net.NetworkCredential cred = new
System.Net.NetworkCredential("SmtpUserName", "SmtpPassword");
c.EnableSsl = true;
c.UseDefaultCredentials = false;
c.Host = "SmtpServer";
c.Port = 465;
c.Credentials = cred;
m.To.Add(new MailAddress("(e-mail address removed)");
m.From = new MailAddress("(e-mail address removed)");
m.Subject = "DotNet email";
m.Body = "Hi Ben" + Environment.NewLine + "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