Hi,
I am trying to send an email in .Net 2 using the
System.Net.Mail.MailMessage class. I am using the code below:
if (_FromName.Length > 0)
Msg.From = new MailAddress(_FromAddress, _FromName);
else
Msg.From = new MailAddress(_FromAddress);
Msg.IsBodyHtml = _HTMLMessage;
Msg.Priority = _Priority;
Msg.Sender = Msg.From;
Msg.DeliveryNotificationOptions =
DeliveryNotificationOptions.None;
//Add the Credentials
SmtpClient client = new SmtpClient();
if (_Authenticate)
{ client.Credentials = new
System.Net.NetworkCredential(_UserName, _Password);
} else
client.UseDefaultCredentials = true;
client.Port = _Port;
client.Host = _ServerName;
client.EnableSsl = _EncryptedConnection;
client.DeliveryMethod = _DeliveryMethod;
if (_DeliveryMethod ==
SmtpDeliveryMethod.SpecifiedPickupDirectory)
client.PickupDirectoryLocation = _PickupDirectory;
if (Asynchronous)
{ client.SendCompleted += new
SendCompletedEventHandler(client_SendCompleted);
client.SendAsync(Msg, (object)Msg);
} else
{
client.Send(Msg);
}
<
Whether I try sending the message synchronously or Asynchronously, the
message does not get sent. If I send a second message, then the first
one is sent. The final message is only sent when I close down the
application.
client.DeliveryMethod is being set to SmtpDeliveryMethod.Network.
Does anybody know what the problem is?
Thankyou
Paul