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 :
Finance | Project Operations, Human Resources, ...
Suggested Answer

Attach an email after it has been sent

(0) ShareShare
ReportReport
Posted on by 50

Is it possible to save sent email and attach it in document attachment after user sent an email from interactive form?

I have the same question (0)
  • Martin Dráb Profile Picture
    237,880 Most Valuable Professional on at

    Yes, it should be possible.

    If you have more questions, give us more context, include the product you're asking about (e.g. AX 2012 or D365FO).

  • Atiraj Profile Picture
    50 on at

    How can I do it with x++?

  • Atiraj Profile Picture
    50 on at

    I want to coding it in D365FO

  • Martin Dráb Profile Picture
    237,880 Most Valuable Professional on at

    Moved from Dynamics AX Forum.

    Please tell us more about the situation.

  • Atiraj Profile Picture
    50 on at

    Now, I can write code to open an email editing form by using this line of code

    SysMailerFactory::sendInteractive(messageBuilder.getMessage())

    What I want to do is, when user click send button, I want to attach email file to document attachment (Docuref).

    How can I do that?

  • Suggested answer
    Martin Dráb Profile Picture
    237,880 Most Valuable Professional on at

    For example:

    System.Net.Mail.MailMessage message = messageBuilder.getMessage();
    
    if (SysMailerFactory::sendInteractive(message))
    {
    	// ... your logic ...
    }

    I don't know what exactly you want to attach. You'll need to convert the message object to what you want.

    Then call one of the attach* methods in DocumentManagement class to actually attach the email to a record.

  • Atiraj Profile Picture
    50 on at

    I want to attach email content that user edit in interactive form, maybe saving it to Html file or Pdf.

    How can I get email content from interactive form?

  • Martin Dráb Profile Picture
    237,880 Most Valuable Professional on at

    Don't you have that in the message?

  • Atiraj Profile Picture
    50 on at

    Thanks Martin!

    Here is line of code that I write to achieve that. Is there any more proper way to do it?

    public void generateEmail(FlxUs_PortJournal _portJournal)
        {
            var builder = new SysMailerMessageBuilder();
            Filename    fileName = _portJournal.CallId   ".htm";
    
            builder.addTo(toEmail);
            builder.addCc(ccEmail);
            builder.setFrom(sysEmailTable.SenderAddr, sysEmailTable.SenderName);
                            
            builder.setSubject(subject);
            builder.setBody(messageBody);
    
            var message = builder.getMessage();
    
            if(SysMailerFactory::getInteractiveMailer().sendInteractive(message))
            {
                str messageString = strFmt("

    From: %1
    To: %2
    CC: %3
    Subject: %4

    %5", message.From.Address, message.To, message.CC, message.Subject, message.Body); System.Text.Encoding encoding = System.Text.Encoding::UTF8; System.Byte[] array = encoding.GetBytes(messageString); System.IO.MemoryStream stream = new System.IO.MemoryStream(array); DocumentManagement::attachFile( _portJournal.TableId , _portJournal.RecId , _portJournal.DataAreaId , "File" , stream , fileName , System.Web.MimeMapping::GetMimeMapping(fileName) , System.IO.Path::GetFileNameWithoutExtension(fileName)); } }

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 584 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 254 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans