# Problem in attaching PDF's in Email through Gatewayscripts

**URL:** <https://forum.inductiveautomation.com/t/problem-in-attaching-pdfs-in-email-through-gatewayscripts/82616>\
**Category:** Ignition\
**Created:** [December 2, 2023, 9:37am UTC](https://forum.inductiveautomation.com/t/problem-in-attaching-pdfs-in-email-through-gatewayscripts/82616 "2023-12-02T09:37:16Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Saranraj\_Chennappan](https://avatars.discourse-cdn.com/v4/letter/s/8c91f0/32.png) [@Saranraj\_Chennappan](https://forum.inductiveautomation.com/u/Saranraj_Chennappan)\
**Post date:** [December 2, 2023, 9:37am UTC](https://forum.inductiveautomation.com/t/problem-in-attaching-pdfs-in-email-through-gatewayscripts/82616/1 "2023-12-02T09:37:16Z")

</div>

Hi,

we are facing some issue while attaching a PDF in Email. Seems no errors in the script. Script running well but i didn't receive mail with PDF attachments.

here with find the code which we are using for your reference.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/4/c4c819a5e7e04d7c99debfd26d201fb7471c19ee.png)

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [December 2, 2023, 10:07am UTC](https://forum.inductiveautomation.com/t/problem-in-attaching-pdfs-in-email-through-gatewayscripts/82616/2 "2023-12-02T10:07:23Z")

</div>

Please post formatted code, not pictures of code. That way we don't have to type it all out again to test or edit in our answers.

> [@Wiki - how to post code on this forum](https://forum.inductiveautomation.com/t/wiki-how-to-post-code-on-this-forum/77831):
>
> This thread is intended as a short help file for all those struggling to post formatted code on the forum. Posting formatted code on the forum (and most others) is as simple as selecting the code and pressing the \</\> button. It works the same as applying Bold or Italic styles to your document. It preserves indentation and applies syntax highlighting. [How to post code]

---

<div class="post-metadata">

**Author:** ![Saranraj\_Chennappan](https://avatars.discourse-cdn.com/v4/letter/s/8c91f0/32.png) [@Saranraj\_Chennappan](https://forum.inductiveautomation.com/u/Saranraj_Chennappan)\
**Post date:** [December 2, 2023, 10:21am UTC](https://forum.inductiveautomation.com/t/problem-in-attaching-pdfs-in-email-through-gatewayscripts/82616/3 "2023-12-02T10:21:05Z")

</div>

Hi,  
Please find the formatted code.

smtp = 'Alarm\_Mail'  
BuildHTML = "

Test

"  
subject = 'test'  
body = BuildHTML   
to = ['sample\_mailid@gmail.com']  
sender = 'TestMail@pdf.com'  
html = 1

params = {'Name': 'Sample\_pdf'}   
a = system.report.executeReport(path = "text",project = "Project\_Name", parameters = params,fileType="pdf")   
attachmentNames = ['text.pdf']

attachmentData=[a]

system.net.sendEmail(smtpProfile=smtp,fromAddr=sender, subject= subject,body = body,html=html,to=to,attachmentNames=attachmentNames,attachmentData=attachmentData)

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [December 2, 2023, 10:26am UTC](https://forum.inductiveautomation.com/t/problem-in-attaching-pdfs-in-email-through-gatewayscripts/82616/4 "2023-12-02T10:26:39Z")

</div>

> [@Saranraj\_Chennappan](#):
>
> Please find the formatted code.

You didn't format it. Please read the linked article and then you can edit your post to fix it.

---

<div class="post-metadata">

**Author:** ![Saranraj\_Chennappan](https://avatars.discourse-cdn.com/v4/letter/s/8c91f0/32.png) [@Saranraj\_Chennappan](https://forum.inductiveautomation.com/u/Saranraj_Chennappan)\
**Post date:** [December 2, 2023, 10:41am UTC](https://forum.inductiveautomation.com/t/problem-in-attaching-pdfs-in-email-through-gatewayscripts/82616/5 "2023-12-02T10:41:16Z")

</div>

Hi,

```auto
smtp = 'Alarm_Mail'
BuildHTML = "

Test

"
subject = 'test'
body = BuildHTML
to = ['sample_mailid@gmail.com']
sender = 'TestMail@pdf.com'
html = 1

params = {'Name': 'Sample_pdf'}
a = system.report.executeReport(path = "text",project = "Project_Name", parameters = params,fileType="pdf")
attachmentNames = ['text.pdf']

attachmentData=[a]

system.net.sendEmail(smtpProfile=smtp,fromAddr=sender, subject= subject,body = body,html=html,to=to,attachmentNames=attachmentNames,attachmentData=attachmentData)

```

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [December 2, 2023, 11:00am UTC](https://forum.inductiveautomation.com/t/problem-in-attaching-pdfs-in-email-through-gatewayscripts/82616/6 "2023-12-02T11:00:09Z")

</div>

1. Presumably **Alarm\_Mail** is the name of an email profile you have set up on the gateway, Config → Networking → Email Settings. Is this correct?
2. On the Email Settings profiles page there is a More ▼ button with a **Test** option. Did you confirm that your email profile is working?

---

<div class="post-metadata">

**Author:** ![Saranraj\_Chennappan](https://avatars.discourse-cdn.com/v4/letter/s/8c91f0/32.png) [@Saranraj\_Chennappan](https://forum.inductiveautomation.com/u/Saranraj_Chennappan)\
**Post date:** [December 4, 2023, 5:02am UTC](https://forum.inductiveautomation.com/t/problem-in-attaching-pdfs-in-email-through-gatewayscripts/82616/7 "2023-12-04T05:02:32Z")

</div>

Yes, Email settings are correct and Email profile also working. I have tested scheduled actions with the same report. only through scripting i didn't receive mail.

---

<div class="post-metadata">

**Author:** ![Saranraj\_Chennappan](https://avatars.discourse-cdn.com/v4/letter/s/8c91f0/32.png) [@Saranraj\_Chennappan](https://forum.inductiveautomation.com/u/Saranraj_Chennappan)\
**Post date:** [December 7, 2023, 4:21am UTC](https://forum.inductiveautomation.com/t/problem-in-attaching-pdfs-in-email-through-gatewayscripts/82616/8 "2023-12-07T04:21:32Z")

</div>

Hi,

Any updates???

Please let me know.
