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

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

Send email using multiple SMTP server

(0) ShareShare
ReportReport
Posted on by 222

Hi,

I have develop batch job to  send emails, using the SMTP server. I have set the email parameter, for testing and its working fine for me. But when try to go live, I have notice there was already email parameters are configure with some abc@test1.com. When I tried to send email with from email address test2.com, I have got authentication error. As the given authentication given for test1.com. Now I need to send the email using other server like xyz@test2.com

If I replace the sender with mine one. Then the other department will complain their email are not going to deliver. I think I need to configure email server at run time, or what may the possibility. 

Please help, Here is the code which I am using to send email.

    public boolean sendEmail(Email emailTo, str emailSub, str emailBody, str CC1, str CC2, str CC3)
    {
        SysMailerMessageBuilder messageBuilder = new SysMailerMessageBuilder();
        SysEmailParameters parameters = SysEmailParameters::find();
        Email fromEmail;
        System.ArgumentException ex;
        try
        {
            fromEmail = "No-reply";
            messageBuilder.setBody(emailBody,true);
            messageBuilder.setSubject(emailSub);
            //messageBuilder.addTo("myletter@company1.com");
            messageBuilder.addTo(emailTo);
            if (CC1!="")
                messageBuilder.addCc(CC1);
            if (CC2!="")
                messageBuilder.addCc(CC2);
            if (CC3!="")
                messageBuilder.addCc(CC3);
            messageBuilder.addCc("xyz@company1.com");
            // Note: not calling setFrom() defaults to the current user for SMTP client, whereas
            // when sent to Outlook any setFrom() value will be ignored since profiles on the client are used
            messageBuilder.setFrom(fromEmail);
            // Open the generated email in the configured client
            // Sends a message interactively, allowing the user to view and modify the message before
            SysMailerFactory::sendNonInteractive(messageBuilder.getMessage());
            // Try using sendNonInteractive method too
        }
        catch (ex)
        {
            throw error(ex.Message);
        }
        return true;
    }

Email setting parameters

pastedimage1654080842080v1.png

I have the same question (0)
  • André Arnaud de Calavon Profile Picture
    299,314 Super User 2025 Season 2 on at
    RE: Send email using multiple SMTP server

    Hi,

    Are you using an email address from a different domain or the same domain but just another mailbox? If it would be from another domain, how would the outgoing mail server for one domain be able to authenticate the other domain?

  • nbhatti2001 Profile Picture
    222 on at
    RE: Send email using multiple SMTP server

    Hi,

    I need to use two different domains for email as different departments have to send email with their own domain. And we can set one domain in in email parameter setting.

    Now question is how I can send email from different domain? As mine and other department domain are different.  

    And I know one domain can't authenticate other domain.

  • André Arnaud de Calavon Profile Picture
    299,314 Super User 2025 Season 2 on at
    RE: Send email using multiple SMTP server

    This would require a customization to be able to setup multiple SMTP settings. I have no experience if this would work or not as the Dynamics 365 instance is also running on a particular tenant.

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 2,122

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 918 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 646 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans