web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Sending emails without Outlook or SSS or Email Router

(0) ShareShare
ReportReport
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

I have the same question (0)
  • ashlega Profile Picture
    34,477 on at

    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)..

  • Suggested answer
    Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    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.

  • Verified answer
    Faisalk Profile Picture
    130 on at

    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

  • Faisalk Profile Picture
    130 on at

    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

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans