The email commands in Python™ allow you to send email.
See Python commands for other commands you can use with GainSeeker.
Contents [Hide] |
Syntax |
Example |
Description/Remarks |
New or changed in GainSeeker version |
email.display(to, subject, body, html=False, attachments=None) |
Displays an interactive email window that is automatically populated by the following parameters: to - the address(es) to whom this email will be sent. Can be either a string or a list of strings (one string per address). subject - the subject line of the email. Must be a string. body - the body of the email, either plain text or HTML. Must be a string. html - sets the formatting
of the email body. attachments - a list of email
attachments. Each item in the list must include a valid file path
and file name. The end user can interact with the email window to change recipients, subject, body text, etc. The email will not be sent until the user clicks to Send it. Email will be sent via the built-in SMTP email function or Microsoft Outlook, depending on the System-wide setting Email send method used and the availability of Microsoft Outlook on the workstation that runs this Python script. This command cannot be used in a Custom Statistic or in a script that is run by GS Console. The value of error.stoponerror determines what happens if there is an error sending the email. If True (the default), the script will halt and an error message window will be displayed. If False, an error message will be printed to the console and the script will continue to run. |
9.1 |
|
email.from_address |
email.from_address = "me@my_company.com" |
Gets/Sets the address from which the email will be sent. When email is sent from Microsoft Outlook, this property is not used. However, best practice is to set the property in case a workstation without Outlook runs this script. |
8.9 |
email.load_defaults() |
email.load_defaults() |
Uses the email settings from System-wide settings to set email.server, email.port, and email.use_ssl. Uses the email settings from the currently logged-in User to set email.from_address, email.username, and email.password. When email is sent from Microsoft Outlook, these properties are not used. However, best practice is to set these properties in case a workstation without Outlook runs this script. |
8.9 |
email.password |
email.password = "password123" |
Gets/Sets the password for email authentication. When email is sent from Microsoft Outlook, this property is not used. However, best practice is to set the property in case a workstation without Outlook runs this script. |
8.9 |
email.port |
email.port = 587 |
Gets/Sets the email port number. Port number must be greater than 0. When email is sent from Microsoft Outlook, this property is not used. However, best practice is to set the property in case a workstation without Outlook runs this script. |
8.9 |
email.reset() |
email.reset() |
Resets all email properties for the email object. All properties are remembered from one sent email to the next unless they are reset or written over. |
8.9 |
email.send(to, subject, body, html=False, attachments=None) |
Sends email using the following parameters: to - the address(es) to whom this email will be sent. Can be either a string or a list of strings (one string per address). subject - the subject line of the email. Must be a string. body - the body of the email, either plain text or HTML. Must be a string. html - sets the formatting
of the email body. attachments - a list of email
attachments. Each item in the list must include a valid file path
and file name. The new email is sent immediately without user interaction. Email will be sent via the built-in SMTP email function or Microsoft Outlook, depending on the System-wide setting Email send method used and the availability of Microsoft Outlook on the workstation that runs this Python script. The value of error.stoponerror determines what happens if there is an error sending the email. If True (the default), the script will halt and an error message window will be displayed. If False, an error message will be printed to the console and the script will continue to run. |
8.9, 9.1 |
|
email.server |
email.server = "smtp.gmail.com" |
Gets/Sets the email server. When email is sent from Microsoft Outlook, this property is not used. However, best practice is to set the property in case a workstation without Outlook runs this script. |
8.9 |
email.use_ssl |
email.use_ssl = True |
Gets/Sets whether or not to use Secure Sockets Layer (SSL) to encrypt connections. Can be set to True (use SSL) or False (do not use SSL - the default). When email is sent from Microsoft Outlook, this property is not used. However, best practice is to set the property in case a workstation without Outlook runs this script. |
8.9 |
email.username |
email.username = "me@my_company.com" |
Gets/Sets the username for email authentication. When email is sent from Microsoft Outlook, this property is not used. However, best practice is to set the property in case a workstation without Outlook runs this script. |
8.9 |
This sample script uses the email settings from the System-wide settings and from the User or group name.
The message body is text (not HTML) and there are no email attachments.
The end user can interact with the email window to change recipients, subject, body text, etc. The email will not be sent until the user clicks to Send it.
email.load_defaults()
email.display("joanne@acme.com", "Daily
email", "This
is the message")
This sample script uses the email settings from the System-wide settings and from the User or group name.
The message body is text (not HTML) and there are no email attachments.
The new email is sent immediately without user interaction.
email.load_defaults()
email.send("joanne@acme.com", "Daily
email", "This
is the message")
This sample script does not use the email settings from the System-wide settings or from the User or group name. The message body is text (not HTML) and there are no email attachments.
email.from_address
= "me@my_company.com"
email.use_ssl = True
email.username = "me@my_company.com"
email.password = "password123"
email.server = "smtp.gmail.com"
email.port = 587
email.send("joanne@acme.com", "Daily
email", "This
is the message")
This sample script uses the email settings from the System-wide settings and from the User or group name. The message body is HTML and there are email attachments.
em_recipientlist
= ["joanne@acme.com", "bob@acme.com"]
em_subject = "Daily
Report"
em_body = "<strong>Please
find attached report</strong> and let me know if there are questions."
em_is_html = True
em_attachments = [file.getuserdoc1() + "rtf_procedures.pdf", "z:\\employees\\help.docx"]
email.load_defaults()
error.stoponerror = False
email.send(em_recipientlist, em_subject, em_body, em_is_html, em_attachments)