locked
Cannot send mail in event receiver RRS feed

  • General discussion

  • how to send mail? the code is fine in windows application, but can not work in event receiver.
    
    public static bool SendMail(string gMailAccount, string password, string to, string subject, string message)
        {
          try
          {
            NetworkCredential loginInfo = new NetworkCredential(gMailAccount, password);
            MailMessage msg = new MailMessage();
            msg.From = new MailAddress(gMailAccount);
            msg.To.Add(new MailAddress(to));
            msg.Subject = subject;
            msg.Body = message;
            msg.IsBodyHtml = false;
            SmtpClient client = new SmtpClient("smtp.gmail.com");
            client.EnableSsl = true;
            client.UseDefaultCredentials = false;
            client.Credentials = loginInfo;
            client.Send(msg);
    
            return true;
          }
          catch (Exception)
          {
            return false;
          }
    
        }
    

     

    thanks in advance.

    Sunday, March 13, 2011 11:10 AM

All replies