Thursday, 23 June 2011

Send Mail in ASP.Net using Mail Message


using System.Net.Mail;

private string SendMail(string from, string fromName, string toEmailId, string subject, string body)
    {
        string RetVal = string.Empty;

        try
        {
            MailMessage ObjMailMessage = new MailMessage();
            MailAddress FromAdrs = new MailAddress(from, fromName);
            ObjMailMessage.From = FromAdrs;
            ObjMailMessage.To.Add(toEmailId);
            ObjMailMessage.IsBodyHtml = true;
            ObjMailMessage.Priority = MailPriority.Normal;
            ObjMailMessage.Subject = subject;
            ObjMailMessage.Body = body;
            SmtpClient smtpClient = new SmtpClient();
            smtpClient.Send(ObjMailMessage);
            RetVal = string.Empty;
        }
        catch (Exception ex)
        {
            RetVal = ex.Message;
        }
        return RetVal;
    }

web.config
<system.net>
      <mailSettings>
            <smtp>
                  <network host="192.168.11.110"/>
            </smtp>
      </mailSettings>
</system.net>

No comments:

Post a Comment