M
mazdotnet
Hi everyone,
I'm coverting some of our code here from the old way of sending mail in
..NET 1.1 to the new .NET 2.0. However, everytime I switch the code to
the new method there is a delay of 1-2 minutes before an email is sent
(this is on my local computer pointing to my local smtp -> localhost).
Anyone knows what the problem could be? BTW my computer in located
behind a firewall and I'm sending test emails to my gmail account and
hotmail account. It seems like the new way always takes around 2
minutes to send the email.
============ Old way ==========
System.Web.Mail.MailMessage MyMail= new
System.Web.Mail.MailMessage();
MyMail.From = "(e-mail address removed)";
MyMail.Subject = "Test";
MyMail.Body = body;
MyMail.BodyFormat = System.Web.Mail.MailFormat.Html;
System.Web.Mail.SmtpMail.SmtpServer = SmtpServer;
MyMail.To = "(e-mail address removed)"
System.Web.Mail.SmtpMail.Send(MyMail);
============ New way ==========
System.Net.Mail.SmtpClient mail = new System.Net.Mail.SmtpClient();
mail.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
mail.UseDefaultCredentials = false;
mail.Host = SMTPServer;
string subject = "Test";
string body;
body = DateTime.Now + "\r\n";
body += comment;
MailAddress sender = new MailAddress(from);
MailMessage mailMessage = new MailMessage();
string[] recipients = to.Split(';');
mailMessage.From = sender;
// Add recipients separated by ;
foreach (string recipient in recipients)
{
mailMessage.To.Add(recipient);
}
mailMessage.Body = body;
mailMessage.Subject = subject;
mail.Send(mailMessage);
Thank you
Maz
I'm coverting some of our code here from the old way of sending mail in
..NET 1.1 to the new .NET 2.0. However, everytime I switch the code to
the new method there is a delay of 1-2 minutes before an email is sent
(this is on my local computer pointing to my local smtp -> localhost).
Anyone knows what the problem could be? BTW my computer in located
behind a firewall and I'm sending test emails to my gmail account and
hotmail account. It seems like the new way always takes around 2
minutes to send the email.
============ Old way ==========
System.Web.Mail.MailMessage MyMail= new
System.Web.Mail.MailMessage();
MyMail.From = "(e-mail address removed)";
MyMail.Subject = "Test";
MyMail.Body = body;
MyMail.BodyFormat = System.Web.Mail.MailFormat.Html;
System.Web.Mail.SmtpMail.SmtpServer = SmtpServer;
MyMail.To = "(e-mail address removed)"
System.Web.Mail.SmtpMail.Send(MyMail);
============ New way ==========
System.Net.Mail.SmtpClient mail = new System.Net.Mail.SmtpClient();
mail.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
mail.UseDefaultCredentials = false;
mail.Host = SMTPServer;
string subject = "Test";
string body;
body = DateTime.Now + "\r\n";
body += comment;
MailAddress sender = new MailAddress(from);
MailMessage mailMessage = new MailMessage();
string[] recipients = to.Split(';');
mailMessage.From = sender;
// Add recipients separated by ;
foreach (string recipient in recipients)
{
mailMessage.To.Add(recipient);
}
mailMessage.Body = body;
mailMessage.Subject = subject;
mail.Send(mailMessage);
Thank you
Maz