Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.

Creating an Outlook/Thunderbird Draft Email including Attachments

kelvin_tsang
6 - Meteoroid

For many times, you want Alteryx to process some data, generate a report, and send to a group of recipients. However, you cannot really trust Alteryx to send directly to recipients because you want to check the report for the last time before it gets dispatched. If Alteryx is going to just generate the report and send to yourself, then you will have to manually forward the email, insert the recipients, remove ”FW: ” from the subject, and clean up the email header of the email body. These manual steps kind of of defeats the purpose of automation.

 

In this tutorial I'm going to share with you how to ask Alteryx to send you a Draft email. That is, an email with the ultimate recipients, Subject and email body already populated for you. It even attaches the newly generated reports that you want to send to recipients. After you receive the email from Alteryx, you can open up the Draft email, review and click send. Below is a sample output:

 

 

kelvin_tsang_1-1594540923148.png

 

Now, to do this, you need to know a little bit of a file format called an eml file. An eml file is a text file with file name ended with eml. The content of the text file is similar to below:

 

MIME-Version: 1.0
X-Unsent: 1
To: anyone@anyone.com
Subject: Draft Email with Attachment
Content-Type: multipart/mixed; boundary="email_boundary"

 

--email_boundary
Content-Type: multipart/alternative; boundary="html_boundary"

 

--html_boundary
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

 

This is an HTML message. Please use an HTML capable mail program to read
this message.

 

--html_boundary
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

 

<html><body>This is an email with <b>attachments</b></body></html>

 

--html_boundary--

 

--email_boundary
Content-Type: application/pdf; name="pdf_attachment.pdf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="pdf_attachment.pdf"

 

[A base 64 encoding of an pdf attachment]

 

--email_boundary

Content-Type: application/vnd.ms-excel; name="excel_attachment.xlsx"
Content-Transfer-Encoding: base64
Content-Disposition: inline; filename="excel_attachment.xlsx"

 

[A base 64 encoding of an Excel attachment]

 

--email_boundary--

 

Here are the description of some key fields:

 

  • MIME-Version: 1.0: Just keep this
  • X-Unsent: 1: This line will make sure the file be opened in your email client in Edit mode. I have tested it in Outlook and it works. If you want this to work in Thunderbird, you will need to install this fix.
  • To: This is the To email address you want the Draft email to pre-populate. This is usually a list of target report recipients.
  • Subject: This is the Subject you want the Draft email to pre-populate.

 

Now, the boundary lines are more difficult to explain. Basically, you need to declare a boundary and describe what you are including. In my example, I'm including an HTML message, and two attachments. Just look at the sample eml message above and you should get a good idea of how to use the boundary.

 

Then, the most tricky part is, you want to include the attachments. You may use Alteryx to generate the reports, and the reports can be PDF, or Excel, or a picture, or a Word document or any file type. I'm going to attached a PDF file and an Excel file in the Draft email. In the declaration, you are going to specify Content-Type of each attachment. That basically tells your operation system what program to use when the recipient double-clicks on each of the attachment.

 

Now, the most interesting part is how you would encode the attachments in the eml message. Alteryx has these very interesting tools just for this purpose: the Blob Input and Blob Convert. You can make use of these to read your PDF file, convert to base64 text, and include in the Draft email.

 

kelvin_tsang_2-1594542513716.png

 

Several things to watch out for when you configure the Alteryx workflow:

 

  1. Empty lines are important in the eml file. However, when you use the Summation tool to concatenate the strings, it removes empty lines. You will need to replace the place holder [BLANK LINE] near the end of the workflow.
  2. When you use the Summation tool to concatenate the strings, make sure you specify \r\n as Separator. It is the carriage return line feed.
  3. In the Blob Convert tool, select Convert from a Blob Field, and select Convert to Base64 encoding Binary Data
  4. In the Output Data configuration, just output as a Comma Separated Value file but you are going to specify a filename with *.eml ending, such as DraftEmail.eml. That's the file you will attach in the Alteryx workflow and send to yourself for final checking.
  5. In the Output Data configuration, make sure you put Never in the Quote Output Fields.

Please leave any comments below if you have any insight/feedback, and I will try to answer them, thanks.

 

30 REPLIES 30
Manik
6 - Meteoroid

got CC and From as well thanks

gavinloi
8 - Asteroid

Can i check how do i view the draft in my mailbox ? seems like the code is running correctly however nothing is in my draft folder.

kelvin_tsang
6 - Meteoroid

gavinloi, after the Alteryx is executed, it should produce an eml file. If you have an email client installed, you may double-click on the output eml file and it should open up.

AmitojSingh
7 - Meteor

This is really useful, I was wondering how can I add my signature details under the body of my email. I wanted to change the colour and size of my signature

 

For Eg

 

"Please find attached the report for the day"

"Thank you and regards"

 

 

"Amitoj Singh

CFS Ltd

21 Ample Avenue"

 

 

AmitojSingh
7 - Meteor

is there a way to pass the email address dynamically, rather than having to hard code it in the first text input tool? Similarly can i add the current date in the subject as a suffix to my report
For Eg "Daily Margin Calcs - yyyy.mm.dd"

AmitojSingh
7 - Meteor

this is similar to what i was trying to achieve to be able to change the To, CC and subject dynamically, where you able to find a solution, please do share i be very keen to see

agnieszka_fatla77
6 - Meteoroid

Hi Suyunn,

did you find any solution of this issue? I've got very similar requirement.

Thank you for any advice.

sgaryali
8 - Asteroid

Hi @kelvin_tsang ,

 

I am also trying something similar like draft emails you shared.

 

But I am not getting the desired result.

 

I am sharing my workflow and inputs files can you please help me in it.

Yuk_Sha
6 - Meteoroid

Hello Suyuun,

Were you able to figure out how to add dynamic email body in the email similar to the example you shared above?

Yuk_Sha
6 - Meteoroid

Hi Kelvin,

 

Thanks a lot for this workflow. Could you please let me know if you were able to solve Suyuun's doubt of creating dynamic email body? I have the same use case and the requirements.

Labels