Office 365: How to send e-mails in SPO using CSOM(I)!

This time I’m sharing a code snippet where you can see how to send e-mails from CSOM code in SharePoint Online (SPO). Please, bear in mind that e-mails can only be sent to Office 365 accounts and not to external e-mail addresses.

string sSiteUrl =

    ConfigurationManager.AppSettings["SPOSiteUrl"];

 

using (SPO_CSOM.ClientContext spoCtx = new SPO_CSOM.ClientContext(sSiteUrl))

{

    //

    //SharePoint Online Credentials

    //

    string sSPOUser =

        ConfigurationManager.AppSettings["SPOUser"];

    string sPassword =

        ConfigurationManager.AppSettings["SPOPassword"];

    SecureString ssPassword = new SecureString();

    foreach (char c in sPassword.ToCharArray())

        ssPassword.AppendChar(c);

    spoCtx.Credentials =

        new SPO_CSOM.SharePointOnlineCredentials(

            sSPOUser, ssPassword);

 

    SPO_CSOM.Utilities.EmailProperties spoEmailProperties = 

        new SPO_CSOM.Utilities.EmailProperties();

    spoEmailProperties.BCC = new List<string> { sSPOUser };

    spoEmailProperties.To = new List<string> { sSPOUser };

    spoEmailProperties.From = sSPOUser;

    spoEmailProperties.Body = "<b>Test E-Mail from CSOM</b>";

    spoEmailProperties.Subject = "E-Mail sent from CSOM";

    SPO_CSOM.Utilities.Utility.SendEmail(spoCtx, spoEmailProperties);

    spoCtx.ExecuteQuery();

     

}

Office 365: Como enviar e-mails desde CSOM en SharePoint Online (I)!

En esta ocasión os comparto un snippet de código en el que podéis ver como enviar correos electrónicos desde la versión .NET del Modelo de Objetos en Cliente (CSOM) en SharePoint Online. Tened en cuenta que los correos no se van a enviar en el caso en el que uséis cuentas de correo electrónico que no sean de Office 365.

string sSiteUrl =

    ConfigurationManager.AppSettings["SPOSiteUrl"];

 

using (SPO_CSOM.ClientContext spoCtx = new SPO_CSOM.ClientContext(sSiteUrl))

{

    //

    //SharePoint Online Credentials

    //

    string sSPOUser =

        ConfigurationManager.AppSettings["SPOUser"];

    string sPassword =

        ConfigurationManager.AppSettings["SPOPassword"];

    SecureString ssPassword = new SecureString();

    foreach (char c in sPassword.ToCharArray())

        ssPassword.AppendChar(c);

    spoCtx.Credentials =

        new SPO_CSOM.SharePointOnlineCredentials(

            sSPOUser, ssPassword);

 

    SPO_CSOM.Utilities.EmailProperties spoEmailProperties = 

        new SPO_CSOM.Utilities.EmailProperties();

    spoEmailProperties.BCC = new List<string> { sSPOUser };

    spoEmailProperties.To = new List<string> { sSPOUser };

    spoEmailProperties.From = sSPOUser;

    spoEmailProperties.Body = "<b>Test E-Mail from CSOM</b>";

    spoEmailProperties.Subject = "E-Mail sent from CSOM";

    SPO_CSOM.Utilities.Utility.SendEmail(spoCtx, spoEmailProperties);

    spoCtx.ExecuteQuery();

     

}