Top  | Previous | Next

system.net.sendEmail

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!

 

information2 This function accepts keyword-style invocation. See also: Functions / Keyword Invocation

Syntax

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

Parameters

String smtp - The 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".

String fromAddr - An email address to have the email come from.

String subject - The subject line for the email

String body - The body text of the email.

Boolean html - A flag indicating whether or not to send the email as an HTML email. Will auto-detect if omitted.

String[] to - A list of email addresses to send to.

String[] attachmentNames - A list of attachment names.

byte[][] attachmentData - A list of attachment data, in binary format.

Integer timeout - A timeout for the email, specified in milliseconds. Defaults to 5 minutes (60,000*5)

String username - If specified, will be used to authenticate with the SMTP host.

String password - If specified, will be used to authenticate with the SMTP host.

String priority - The X-Priority field in the header of the email.

Returns

nothing

Scope

All

Examples

Example 1:

 

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

 

Example 2:

 

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

Example 3:

 

# This code ask the user for an attachment file and attach 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])