Skip to main content
Version: 7.9

system.net.sendEmail

This function is used in Python Scripting.

Description

Sends an email through the given SMTP server. Note that this email is relayed first through the Gateway - the client host machine doesn't need network access to the SMTP server.

You can send text messages to cell phones and pagers using email. Contact your cell carrier for details. If you had a Verizon cell phone with phone number (123) 555-8383, for example, your text messaging email address would be: 1235558383@vtext.com. Try it out!

Client Permission Restrictions

This scripting function has no Client Permission restrictions.

Syntax

tip

This function accepts keyword arguments.

system.net.sendEmail(smtp, fromAddr, subject, body, html, to, attachmentNames, attachmentData, timeout, username, password, priority, smtpProfile, cc, bcc, retries)

New in 7.9.5
Some of these parameters are new!

Parameters

TypeParameterDescription
StringsmtpThe address of an SMTP server to send the email through, like "mail.example.com". A port can be specified, like "mail.example.com:25". SSL can also be forced, like "mail.example.com:25:tls".
StringfromAddrAn email address to have the email come from.
StringsubjectThe subject line for the email.
StringbodyThe body text of the email.
BooleanhtmlA flag indicating whether or not to send the email as an HTML email. Will auto-detect if omitted.
String[]toA list of email addresses to send to.
String[]attachmentNamesA list of attachment names. Attachment names must have the correct extension for the file type or an error will occur.
byte[][]attachmentDataA list of attachment data, in binary format.
IntegertimeoutA timeout for the email, specified in milliseconds. Defaults to 300,000 milliseconds (5 minutes).
StringusernameIf specified, will be used to authenticate with the SMTP host.
StringpasswordIf specified, will be used to authenticate with the SMTP host.
StringpriorityPriority for the message, from "1" to "5", with "1" being highest priority. Defaults to "3" (normal) priority.
StringsmtpProfileIf specified, the named SMTP profile defined in the Gateway will be used. If this keyword is present, the smtp, username, and password keywords will be ignored.
String[]ccA list of email addresses to carbon copy. Only available if a smtpProfile is used.
String[]bccA list of email addresses to blind carbon copy. Only available if a smtpProfile is used.
IntegerretriesThe number of additional times to retry sending on failure. Defaults to 0. Only available if a smtpProfile is used.
String[]replyToAn optional list of addresses to have the recipients reply to. If omitted, this defaults to the from address.

Returns

Nothing

Scope

All

Code Examples

Code Snippet
# This code would send a simple plain-text email to a single recipient, with no attachments
body = "Hello, this is an email."
recipients = ["bobsmith@mycompany.com"]
system.net.sendEmail("mail.mycompany.com",
"myemail@mycompany.com", "Here is the email!", body, 0, recipients)
Code Snippet
# This code would send an HTML-formatted email to multiple recipients (including
# cellphones) with no attachments
body = "<HTML><BODY><H1>This is a big header</H1>"
body += "And this text is <font color='red'>red</font></BODY></HTML>"
recipients = ["bobsmith@mycompany.com", "1235558383@vtext.com", "sally@acme.org", "1235557272@vtext.com"]
myuser = "mycompany"
mypass = "1234"
system.net.sendEmail(smtp="mail.mycompany.com", fromAddr="myemail@mycompany.com",
subject="Here is the email!", body=body, html=1, to=recipients, username=myuser, password=mypass)
Code Snippet
# This code ask the user for an attachment file and attaches the file.
filePath = system.file.openFile()
if filePath != None:
# This gets the filename without the C:\folder stuff
fileName = filePath.split("\\")[-1]
fileData = system.file.readFileAsBytes(filePath)
smtp = "mail.mycompany.com"
sender = "myemail@mycompany.com"
subject = "Here is the file you requested"
body = "Hello, this is an email."
recipients = ["bobsmith@mycompany.com"]
system.net.sendEmail(smtp, sender, subject, body, 0, recipients, [fileName], [fileData])
Code Snippet
# This code would send an HTML-formatted email to multiple recipients, including a cc, with no attachments,
# using an smtp server defined in the Gateway
body = "<HTML><BODY><H1>This is a big header</H1>"
body += "And this text is <font color='red'>red</font></BODY></HTML>"
recipients = ["bobsmith@mycompany.com", "1235558383@vtext.com", "sally@acme.org", "1235557272@vtext.com"]
cc_recipients = ["annejones@mycompany.com"]
smtp_server = "mySmtpServer"
system.net.sendEmail(smtpProfile=smtp_server, fromAddr="myemail@mycompany.com", subject="Here is the email!", body=body, html=1, to=recipients, cc=cc_recipients)