---
title: "system.net.sendEmail"
description: "Sends an email through the given SMTP server."
---
# system.net.sendEmail
> Sends an email through the given SMTP server.
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.
Note that you can use this function to send emails as text messages. Most phone service providers offer a domain that can be used to convert emails into text messages. For example: `1234567890@phone.domain.com`. Contact your cell carrier for details.
Ignition now supports more attachment file formats with associated MIME type mappings, including `.ics`, `.ifb`, `.otf`, and `.wav`. Additional or modified mappings may be specified in `\webserver\webdefault.xml`:
```python title="Example"
pwn
application/vnd.3m.post-it-notes
```
## Client Permission Restrictions
This scripting function has no [Client Permission](../../../ignition-modules/vision/vision-project-properties/vision-project-properties.md#vision-permissions-properties) restrictions.
## Syntax
:::tip
This function accepts [keyword arguments](platform/scripting/python-scripting/user-defined-functions.md#keyword-arguments).
:::
`system.net.sendEmail(smtp, fromAddr, [subject], [body], [html], to, [attachmentNames], [attachmentData], [timeout], [username], [password], [priority], [smtpProfile], [cc], [bcc], [retries], [replyTo])`
### Parameters
| Type | Parameter | Description |
|-------|------------|-------------|
| 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`. STARTTLS can also be forced, like `mail.example.com:587:tls`. |
| String | `fromAddr` | An email address to have the email come from. |
| String | `subject` | The subject line for the email. [optional] |
| String | `body` | The body text of the email. [optional] |
| Boolean | `html` | A flag indicating whether or not to send the email as an HTML email. Will auto-detect if omitted. [optional] |
| List[String] | `to` | A list of email addresses to send to. This parameter becomes optional if either the `cc` or `bcc` parameter is specified. |
| List[String] | `attachmentNames` | A list of attachment names. Attachment names must have the correct extension for the file type or an error will occur. [optional] |
| List[Byte] | `attachmentData` | A list of attachment data, in binary format. [optional] |
| Integer | `timeout` | A timeout for the email, specified in milliseconds. Defaults to 300,000 milliseconds (5 minutes). [optional] |
| String | `username` | If specified, will be used to authenticate with the SMTP host. [optional] |
| String | `password` | If specified, will be used to authenticate with the SMTP host. [optional] |
| String | `priority` | Priority for the message, from "1" to "5", with "1" being highest priority. Defaults to "3" (normal) priority. [optional] |
| String | `smtpProfile` | If 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. [optional] |
| List[String] | `cc` | A list of email addresses to carbon copy. Only available if an `smtpProfile` is used. [optional] |
| List[String] | `bcc` | A list of email addresses to blind carbon copy. Only available if an `smtpProfile` is used. [optional] |
| Integer | `retries` | The number of additional times to retry sending on failure. Defaults to 0. Only available if an `smtpProfile` is used. [optional] |
| List[String] | `replyTo` | An optional list of addresses to have the recipients reply to. If omitted, this defaults to the from address. [optional] |
### Returns
Nothing
### Scope
Gateway, Vision Client, Perspective Session
## Code Examples
```python title="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)
```
```python title="Example #2"
# This code would send an HTML-formatted email to multiple recipients (including
# cellphones) with no attachments
body = "
This is a big header
"
body += "And this text is red"
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)
```
```python title="Example #3"
# 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])
```
```python title="Example #4"
# 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 = "This is a big header
"
body += "And this text is red"
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)
```