# Cannot send mail from ignition gateway

**URL:** <https://forum.inductiveautomation.com/t/cannot-send-mail-from-ignition-gateway/58794>\
**Category:** Ignition\
**Tags:** ignition80, perspective\
**Created:** [April 25, 2022, 5:31am UTC](https://forum.inductiveautomation.com/t/cannot-send-mail-from-ignition-gateway/58794 "2022-04-25T05:31:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![vani161998](https://avatars.discourse-cdn.com/v4/letter/v/ee7513/32.png) [@vani161998](https://forum.inductiveautomation.com/u/vani161998)\
**Post date:** [April 25, 2022, 5:31am UTC](https://forum.inductiveautomation.com/t/cannot-send-mail-from-ignition-gateway/58794/1 "2022-04-25T05:31:32Z")

</div>

hi,  
I am trying to send a mail with attached file. here is my code:

```auto
fileData=system.db.runScalarQuery("SELECT file_bytes FROM reports where row_id='42'")
fileName ="FireReport.xlsx"
smtpProfile = "Alert_Mail"
sender = "Aryavani.M@gmail.com"
subject = "FireTest_Report"
body = "Hi,Please find the attachment."
recipients = ["Aryavani.M@gmail.com"]
system.net.sendEmail(smtpProfile,sender,subject,body,0,recipients,[fileName],[fileData])

```

i am getting an error as:  
**Caused by: com.sun.mail.util.MailConnectException: Couldn’t connect to host, port: Alert\_Mail, 25; timeout 10000;**

**if i use the below code i can connect and send mail:**  
body = “Hello, this is an email.”  
recipients = [“[Aryavani.M@gmail.com](mailto:Aryavani.M@gmail.com)”]  
system.net.sendEmail(smtpProfile=“Alert\_Mail”,  
fromAddr= “[Aryavani.M@gmail.com](mailto:Aryavani.M@gmail.com)”,subject= “Here is the email!”, body=body, html=0, to=recipients)

---

<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:** [April 25, 2022, 6:09am UTC](https://forum.inductiveautomation.com/t/cannot-send-mail-from-ignition-gateway/58794/2 "2022-04-25T06:09:16Z")

</div>

`system.net.sendEmail(smtpProfile,sender,subject,body,0,recipients,[fileName],[fileData])`

For a start remove the `[]` square brackets. Those are used in the manual to show optional parameters. You don’t actually use them in your script where they would indicate a list or array.

* * *

Tip: use the `</>` code formatting button when posting code. This will preserve indentation and give you free syntax highlightng. You can use the edit link (pencil icon) to fix the post.

---

<div class="post-metadata">

**Author:** ![vani161998](https://avatars.discourse-cdn.com/v4/letter/v/ee7513/32.png) [@vani161998](https://forum.inductiveautomation.com/u/vani161998)\
**Post date:** [April 25, 2022, 6:24am UTC](https://forum.inductiveautomation.com/t/cannot-send-mail-from-ignition-gateway/58794/3 "2022-04-25T06:24:00Z")

</div>

tried removing [] square brackets ,but i am facing the same error. i can able to send normal mail with body . when try to attach the file the error is coming.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [April 25, 2022, 1:08pm UTC](https://forum.inductiveautomation.com/t/cannot-send-mail-from-ignition-gateway/58794/4 "2022-04-25T13:08:00Z")

</div>

Your smtpProfile doesn’t seem to have a proper SMTP server named (host). Since you are trying to use a gmail “From” address, you will need to follow google’s instructions for setting up SMTP. (If still possible–I vaguely recall reading that they were doing away with it.)

---

<div class="post-metadata">

**Author:** ![KathyApplebaum](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kathyapplebaum/32/7261_2.png) [@KathyApplebaum](https://forum.inductiveautomation.com/u/KathyApplebaum)\
**Post date:** [April 25, 2022, 5:29pm UTC](https://forum.inductiveautomation.com/t/cannot-send-mail-from-ignition-gateway/58794/5 "2022-04-25T17:29:06Z")

</div>

What the others said.

But it also looks like you are confusing two of the parameters. If you look in [the docs](https://docs.inductiveautomation.com/display/DOC81/system.net.sendEmail), the first parameter is the URL of an actual SMTP server, like [smtp.gmail.com](http://smtp.gmail.com). Further down, the parameter **smtpProfile** is for your predefined profile in the gateway, which I’m guessing “Alert\_mail” might be.

Since you don’t want to use all these parameters, use the keyword style invocation. It will also be easier for you to troubleshoot later on. Check the code snippets in the docs link above for how to do that.
