Wednesday, 6 May 2015

How to access SharePoint server “Outgoing E-Mail Settings” from code?

Outgoing email setting are configured in central administration at path:

Central Admin -> System Settings -> Configure outgoing e-mail settings

Below is the code to access outgoing e-mail settings using object model:

//Get the site ID
Guid siteID = SPContext.Current.Site.ID;
protected string GetSMTPHostName()
{
    using (SPSite site = new SPSite(siteID))
    {
      //Get the SMTP host name from “Outgoing e-mail settings”
      return site.WebApplication.OutboundMailServiceInstance.Parent.Name;
    }
}
protected string GetFromEmailID()
{
    using (SPSite site = new SPSite(siteID))
    {
      //Get the “from email address” from “Outgoing e-mail settings”
      return site.WebApplication.OutboundMailSenderAddress;

    }
}

Namespace: Microsoft.SharePoint.Administration
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...