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();

     

}

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

  1. Pingback: Office 365: How to send e-mails in SPO using CSOM(II)! | Pasión por la tecnología...

  2. Pingback: SharePoint & Office 365: Resumen de posts (XII)! | Pasión por la tecnología...

Responder

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión / Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión / Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión / Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión / Cambiar )

Conectando a %s