Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

Sending emails without Outlook or SSS or Email Router

Posted on by 130

Hi all,

I am looking for the options on how to send an email out to customers when a record is created within D365 CRM. On creation of the record, we need to send an email out to the customer to acknowledge. This is very simple if we use Outlook, SSS or Email router but unfortunately, all easy routes are currently blocked and we need to deploy this solution using a) CRM plugin or b) via web services.

I would like to know how I can achieve the above two and also if there is any other workaround and what exactly is needed apart from exchange mailbox which is already available. This is for D653 Online whereas exchange is on prem.

Appreciate your comments and solution.

*This post is locked for comments

  • Faisalk Profile Picture
    Faisalk 130 on at
    RE: Sending emails without Outlook or SSS or Email Router

    Hi Alex,

    Hi Aric,

    We won't have the SMTP ports exposed in our case so this means i need to stick to the WCF route.

    The other option might be that technet.microsoft.com/.../mt622059.aspx but not sure if this will work in my case.

    Thanks

  • Verified answer
    Faisalk Profile Picture
    Faisalk 130 on at
    RE: Sending emails without Outlook or SSS or Email Router

    Hi Aric,

    To use above we would need the ports to be exposed - right ?

    We won't have the SMTP ports exposed in our case so not sure if I can use above may be I will need to stick to the WCF route here.

    The other option might be that technet.microsoft.com/.../mt622059.aspx but not sure if this will work in my case.

    Thanks

  • Suggested answer
    Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: Sending emails without Outlook or SSS or Email Router

    You might be able to do this with Flow.

    If not, you can have use System.Net.Mail:

           public int SendEmail()

           {

               SmtpClient client = new SmtpClient(MailServer, 25);

               client.DeliveryMethod = SmtpDeliveryMethod.Network;

               client.Credentials = new System.Net.NetworkCredential(UserName, Password);

               int retVal = 0;

               try

               {

                   client.Send(message);

               }

               catch (System.Net.Mail.SmtpException ex)

               {

                   Trace.AddLog(EventLevel.Error, DateTime.Now, "Messaging", "SendEmail", "client.Send", ex.Message, "System.Net.Mail.SmtpException", string.Empty);

               }

               catch (System.Exception ex)

               {

                   Trace.AddLog(EventLevel.Error, DateTime.Now, "Messaging", "SendEmail", "client.Send", ex.Message, string.Empty, string.Empty);

                   // System.Diagnostics.EventLog.WriteEntry("ExchangeSync", ex.Message, System.Diagnostics.EventLogEntryType.Error);

               }

               return retVal;

           }

    To Create the Email Message, you can use the following Syntax:

    // From, To, Cc and Bcc are in the following Format: John Doe [john.doe@domain.com]

           public void CreateEmailMessage(string From, string To, string Cc, string Bcc, string Subject, string Body)

           {

               message = new MailMessage();

               int BracketPos = 0; string eMailAddress = "", DisplayName = "";

               BracketPos = From.IndexOf("[");

               if (BracketPos > 0)

               {

                   eMailAddress = From.Substring(BracketPos + 1, From.Length - BracketPos - 2);

                   DisplayName = From.Substring(0, BracketPos);

                   message.From = new MailAddress(eMailAddress, DisplayName);

               }

               else

                   message.From = new MailAddress(From, From);

               BracketPos = To.IndexOf("[");

               if (BracketPos > 0)

               {

                   eMailAddress = To.Substring(BracketPos + 1, To.Length - BracketPos - 2);

                   DisplayName = To.Substring(0, BracketPos);

                   message.To.Add(new MailAddress(eMailAddress, DisplayName));

               }

               else

                   message.To.Add(new MailAddress(To, To));

               if (!string.IsNullOrEmpty(Cc))

               {

                   BracketPos = Cc.IndexOf("[");

                   if (BracketPos > 0)

                   {

                       eMailAddress = Cc.Substring(BracketPos + 1, Cc.Length - BracketPos - 2);

                       DisplayName = Cc.Substring(0, BracketPos);

                       message.CC.Add(new MailAddress(eMailAddress, DisplayName));

                   }

                   else

                       message.CC.Add(new MailAddress(Cc, Cc));

               }

               if (!string.IsNullOrEmpty(Bcc))

               {

                   BracketPos = Bcc.IndexOf("[");

                   if (BracketPos > 0)

                   {

                       eMailAddress = Bcc.Substring(BracketPos + 1, Bcc.Length - BracketPos - 2);

                       DisplayName = Bcc.Substring(0, BracketPos);

                       message.Bcc.Add(new MailAddress(eMailAddress, DisplayName));

                   }

                   else

                       message.Bcc.Add(new MailAddress(Bcc, Bcc));

               }

               message.Subject = Subject;

               message.Body = Body;

               message.IsBodyHtml = true;

           }

    Hope this helps.

  • ashlega Profile Picture
    ashlega 34,475 on at
    RE: Sending emails without Outlook or SSS or Email Router

    Hi,

     you just need to keep in mind that sandbox plugins (and, therefore, any plugin you deploy in the online environment) will have limitations:

    msdn.microsoft.com/.../gg334752.aspx

     But you can still use a plugin to access a web server/web service:

    msdn.microsoft.com/.../gg509030.aspx

     So, if you do need to use a plugin in your scenario, you'll just need to make sure you have a web service somewhere that will be available on a dns name and that will be accessible over http/https. It could be a "proxy" service that will, then, forward those requests to the email server.. or it could be an exchange web service, I guess(if it's already exposed on the internet in your organization)..

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Complete!

🔔 Be sure to subscribe to the new forums you are interested in to stay up to date! 🔔

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,134 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 229,928 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans