How to change default subject of the email when sending mail in Dynamics 365 Business Central – Customization

Dynamics 365 Business Central

Hi, Readers.
Today I would like to talk about how to change default subject of the email when sending mail in Busienss Central.

People in businesses send information and documents, such as sales and purchase orders and invoices, by email every day. Administrators can connect one or more email accounts to Business Central, letting you send documents without having to open an email app.

Test Video:

And an older video from Microsoft:

How to email documents in Dynamics 365 Business Central

PS: Email capabilities in Business Central are for outbound messages only. You can’t receive replies, that is, there’s no “Inbox” page. More details: Set Up Email

It’s a very handy tool, and for email addresses, we’ve discussed Change default customer/vendor email address when sending emails before. Recently I was asked a new interesting question about this, can the default subject of the email be changed?

I did a simple investigation and found out that this information is generated in codeunit 9520 “Mail Management” -> procedure SendViaEmailModule().
PS: my test version: W1 21.4 (Platform 21.0.52534.53527 + Application 21.4.52563.52602)

So we can use events in the same procedure, for example:
OnSendViaEmailModuleOnAfterCreateMessage(Message, TempEmailItem);

And the key method is Message.SetSubject();

Let me do a simple test, add the current username after the defaul subject.

Test Video:

Very simple, isn’t it? Give it a try!!!😁

Source Code:

codeunit 50100 ZYEmailHandler
{
    [EventSubscriber(ObjectType::Codeunit, Codeunit::"Mail Management", 'OnSendViaEmailModuleOnAfterCreateMessage', '', false, false)]
    local procedure OnSendViaEmailModuleOnAfterCreateMessage(var Message: Codeunit "Email Message"; var TempEmailItem: Record "Email Item");
    begin
        Message.SetSubject(TempEmailItem.Subject + ' From ' + UserId);
    end;
}

END

Hope this will help.

Thanks for reading.

ZHU

コメント

Copied title and URL