Sending sales order ack with specified FROM address

I’d like to override the from address in the SalesOrderAck email. I can successfully call the request below which sends an email with the sales order ack attached. However it only uses the “default from email field” in Mail Settings Maintenance. Epicor support says it isn’t possible and that it’s a SendGrid issue. Their claim seems inaccurate because in the second screenshot below I’m able to specify the from address in the TestMailSend function which is used in Mail Settings Maintenance.

Maybe it isn’t possible to include FROM ADDRESS in SubmitToAgent, but to me it’s simply because Epicor dev hasn’t included that attribute.

Anyone have anything to add to this?

Can’t help with overriding using SubmitToAgent, but I’ve got a function that can send an Order Acknowledgment from any specified domain email. Not sure if it works for Cloud/SaaS, but it works great on-prem. Would that work for you?

2 Likes

I assumed that was impossible to veer from the default email field in Maintenance when using the email icon. We kick off the order ack in a Data directive auto print. We use APR for the routing which allows you to set the FromEmail address.

Star Wars Disney Plus GIF by Disney+

Kevin, yes I’d like to see that function if you’re ok sharing. We are also on-prem. I’m still pretty new to Epicor/Kinetic dev so I’ll have to figure out how to add the function.

1 Like

I have one as well that works slightly different.

Explain in detail so we can guide you best how to proceed.

Functions:

Mine:
https://www.epiusers.help/t/lets-share-useful-functions-sharing-is-caring/100371/2

@kve :
https://www.epiusers.help/t/lets-share-useful-functions-sharing-is-caring/100371/43

2 Likes

Here’s the function. Pass in Send From address, recipients, email body/subject, and order num, fires off an email with Sales Order Acknowledgement.
ReportMailer.efxb (7.5 KB)

So that one uses the Ice.Mail.SmtpMailer() Function, I’ve never actually gotten that to work with multiple emails, just the default one set up in Company Maintenance. The one in the .efxb I posted uses the System.Net.Mail assembly and works just a little differently. Using that, you can send using any domain email (which is why I am not sure it works in the cloud).

Here’s the function code for that one (with values hard-coded, not set as parameters):

//using System.Net;
//using System.Net.Mail;


//_ Set up Email Message
using ( var message = new MailMessage() ) {

    string sendName = "Display Name";
    string sendFrom = "myEmail@company.com";
    message.From = new MailAddress( sendFrom, sendName ); //Display Name is optional

    message.To.Add(new MailAddress( "customer@email.com" ));
    message.CC.Add(new MailAddress( "customerCC@email.com" ));
    message.Bcc.Add(new MailAddress( "blindCopy@company.com" ));

    message.Subject = $"Sales Order Acknowledgment {orderNum}";

    message.IsBodyHtml = true;
    message.Body = "<p>Your Sales Order Has Been Received and Processed</p>";
    
    string myAttachment = @"C:\Path\To\Attachment.csv";
    message.Attachments.Add(new Attachment( myAttachment ));


    //_ Send Email
    using ( var smtp = new SmtpClient( "smtp.office365.com", 587 ) ) {

        try {

            smtp.EnableSsl = true;
            smtp.Credentials = new NetworkCredential( sendFrom, "SendFromPassword" ); //NetworkCredential stores the password as SecureString
            smtp.Send( message );

        } 
        catch ( Exception ex ) {

            string logName = @"C:\EpicorData\Logs\smtpErrors.log";
            string logDtls = $"\n{DateTime.Now:G}:\n{ex.Message}\n";
            System.IO.File.AppendAllText( logName, logDtls );

        }
        finally {

            System.IO.File.Delete( myAttachment );
        }
    }
}

This is great. Thanks for the code. I’ll try it out when I get a chance.

You just have to have the send on behalf of permissions set properly for your from addresses.

It does.

1 Like

Is that an Epicor thing or a domain thing?

Nice

Domain/O365/Equivalent

1 Like

You may have to include a DMARC record too.

1 Like

I have the SendEmail code/function working but need some assistance with the SaveOrderAck function. I’ve only narrowed it down to somewhere in the GetASalesOrderPDF function. The only value I’ve modified is “ReportStyleNum = 1001”. Anything else obvious that I’m missing?

See the Postman response below.

1 Like

Looks like the exception occurs on soa.RunDirect(…)

1 Like

Okay I just re-tested this, looks like I had the “Required Transaction” checkbox checked on the SaveOrderAck function. Not sure why I checked that, I don’t have it checked in my production version. Try unchecking that box on the function.

That was it. Thanks for your time on this!

1 Like

Ok Kevin I’m getting some odd behavior on this. Looks like it’s related to the Epicor user that’s logged in.

When I run the code from the screenshot it processes correctly.

When another user runs the code the ordernum param is correct, the PDF file name is correct (and eventually attached to the email), but the actual report rendered within the PDF is of the wrong sales order. It’s actually always the same order, no matter which ordernum we send in to the function. Is this somehow related to permissions when calling soa.RunDirect() ? Or is this an issue with the Db.SysRptLst.Join code?