20

Is it possible for me to pull the values that are in:

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

from my code behind using the object model?

23

Make sure that you have already configured the “Outgoing e-mail settings”.

//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;

    }
}

   //you can also get other properties similarly...
7

Yes, look for properties of SPAdministrationWebApplication, you can access it using SPAdministrationWebApplication.Local. Properties are:

OutboundMailCodePage

OutboundMailReplyToAddress

OutboundMailSenderAddress

OutboundMailServiceInstance

OutboundSmsServiceAccount


Namespace: Microsoft.SharePoint.Administration

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

If you want to update the settings, you need to call UpdateMailSettings method.

2

In SharePoint you can configure the outgoing email settings at two locations in the Central Admin.

  • First, there is a global setting at Central Admin -> System Settings -> Configure outgoing e-mail settings (that is what was asked in the original question).

  • Second, you can configure an alternative setting for each of the web applications at Central Admin -> Application Management -> Manage web applications -> (select the web application you would like to configure) -> (select the General Settings drop-down button at the ribbon) -> Outgoing E-mail.

Via the code from Falak Mahmood you can access this later one.

If you need to access the global settings, you can do it either via the SPGlobalAdmin class:

var globalAdmin = new Microsoft.SharePoint.Administration.SPGlobalAdmin()
var smtpServer = globalAdmin.OutboundSmtpServer
var mailFromAddress = globalAdmin.MailFromAddress
var mailReplyToAddress = globalAdmin.MailReplyToAddress

Or you can access the corresponding properties of the SPAdministrationWebApplication.Local instance (of type SPAdministrationWebApplication, subtype of SPWebApplication), like OutboundMailSenderAddress or OutboundMailReplyToAddress.

Note, that the mail related properties of SPGlobalAdmin are available only as getter methods. If you want to change them, you can either call the UpdateMailSettings method:

SPAdministrationWebApplication.Local.UpdateMailSettings("smtp.company.com", "spsender@company.com", "noreply@company.com", 65001);

or set the corresponding properties directly, like

var localAdminWebApp = SPAdministrationWebApplication.Local;
localAdminWebApp.Local.OutboundMailSenderAddress = "spsender@company.com";
localAdminWebApp.OutboundMailReplyToAddress = "noreply@company.com";
localAdminWebApp.Update();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.