We can send mail to any where with the help of c# custom code. Below given code use setting from ‘Outgoing e-mail setting’. This is out of box functionality of SharePoint. Therefore before using this code, configure this from Central Administration.
Libraries which you have to add above the code.
using System.Net.Mail;
using Microsoft.SharePoint;
Below code shows functionality to send mail.
public void SendMail()
{
try
{
Microsoft.SharePoint.Administration.SPGlobalAdmin globAdmin = new Microsoft.SharePoint.Administration.SPGlobalAdmin();
MailMessage objEmail = new MailMessage(FromMail, ToMail,Subject,Body);
objEmail.IsBodyHtml = true;
objEmail.Priority = MailPriority.Normal;
SmtpClient smtp = new SmtpClient(globAdmin.OutboundSmtpServer);
smtp.Send(objEmail);
}
catch
{
throw;
}
}
No comments:
Post a Comment