System.Net.Mail

  • Thread starter Thread starter Paul Cheetham
  • Start date Start date
P

Paul Cheetham

Hi,

I am trying to send an email using the MailMessage Class.
Everything is working, except that it will not send the message
immediately.
When I try to send the message nothing happens. If I then send another
message, the first one is sent, and the last one is not.
On closing the application the last message gets sent.

I have tried Dsiposing of the MailMessage object after sending, but that
doesn't appear to make any difference.

I am using the Network delivery method, so the message should be sent
directly to the specified SMTP server.


Does anybody have any insight to this, it's driving me mad.


Thankyou


Paul
 
This is my Sending code.
This is part of a class, and all the variables beginning with an
underscore are protected class members.

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;

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);
}
<


I get the same problem whether I try send synchronously or asynchronously.


Thanks.

Paul







-->
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top