Friday, August 10, 2012

Getting the SMTP name for Web app


In place of explicitly hardcoding the SMTP name in the SharePoint to send mail, its always better to get the SMTP configured for the Web App, so that in future if due to any reason its getting changes, there will not be any impact on the application


private string GetSmtpServer()
{
 SPWebApplication parentWebAppp = SPContext.Current.Site.WebApplication;
 if (parentWebAppp != null)
 {
   return parentWebAppp.OutboundMailServiceInstance.Server.Address;
 }
return string.Empty;
}

No comments:

Post a Comment