Send Mails in SharePoint Event Receiver
After I getting the user, email id from
item( described in Previous Post) . Now I need to send mail to the user, I tried
lot of ways to send mails and finally I realise that below code is best for my
scenario to send mails.
SmtpClient
smtpClient = new SmtpClient();
smtpClient.Host =
properties.Web.Site.WebApplication.OutboundMailServiceInstance.Server.Address;
MailMessage
mailMessage = new MailMessage(MailFrom, mailTo);
mailMessage.Subject
= MailSubject;
mailMessage.Body
= MailBody;
mailMessage.IsBodyHtml
= true;
smtpClient.Send(mailMessage);
here smtpClient.Host is getting the local
mail server address and we include from, to and subject, body in MailMessage
and finaly send the message using smtpClient.Send(mailMessage), and don’t forgot
to include try catch blocks. Good luck.
Comments
Post a Comment