Ajai Ajai

Ajai Ajai

  • NA
  • 120
  • 0

After send mail 3 times server hang

Dec 27 2014 5:36 AM

I am using MVC 4.0 (Visual Studio 2010).

I am facing a problem to send the mail, first 3 mails send very frequently (within min) and get the success response but when we press again i.e 4th times then server like hang (On browser running continuously, and after 4-5 min get the response in browser. can any one help me to understand the exact problem. Also read in details on micro soft site "After calling SendAsync, you must wait for the e-mail transmission to complete before attempting to send another e-mail message using Send or SendAsync.". then must be create the problem to send the second and third mail also, why its causing after 4th mail.

Network credentials given from AWS server. This may be a AWS server issue, as last time not send the mail due to AWS Zone restriction.

Here is the code :-

try
{
MailMessage mailMsg = new MailMessage();
mailMsg.To.Add(new MailAddress(inv.Investor.Email));
mailMsg.From = new MailAddress("[email protected]", "Vega Management"); // From Content
mailMsg.Subject = strSubject; // Subject and multipart/alternative Body
mailMsg.Body = strContent;
mailMsg.IsBodyHtml = true;
SmtpClient smtpClient = new SmtpClient("email-smtp.us-west-2.amazonaws.com", Convert.ToInt32(25));
smtpClient.EnableSsl = true;
smtpClient.Timeout = 10000;
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.UseDefaultCredentials = false;
System.Net.NetworkCredential credentials = new System.Net.NetworkCredential("AKIAIU6T5S3", "Ap7g+MUMSOzD");
smtpClient.Credentials = credentials;
smtpClient.Send(mailMsg);
//string strMessageCallBack = "Test Message 1";
//smtpClient.SendAsync(mailMsg,);
mailMsg.Dispose();
smtpClient.Dispose();
return 1;
}
catch { return -2; }

Answers (2)