Cannot send mail from ignition gateway

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

fileData=system.db.runScalarQuery("SELECT file_bytes FROM reports where row_id='42'")
fileName ="FireReport.xlsx"
smtpProfile  = "Alert_Mail"
sender = ""
subject = "FireTest_Report"
body = "Hi,Please find the attachment."
recipients = [""],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 = [“”]“Alert_Mail”,
fromAddr= “”,subject= “Here is the email!”, body=body, html=0, to=recipients),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.

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.

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.)


What the others said.

But it also looks like you are confusing two of the parameters. If you look in the docs, the first parameter is the URL of an actual SMTP server, like 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.