RPA.Email.ImapSmtp

ImapSmtp is a library for sending, reading, and deleting emails. ImapSmtp is interfacing with SMTP and IMAP protocols.

*About criteria argument*

Various keywords like List Messages and Move Messages have keyword argument called criterion which can be used to filter emails according to given criteria.

Syntax needs to according to specification and more information about that can be read from https://robocorp.com/docs/development-guide/email/sending-emails-with-gmail-smtp#listing-email-messages-by-criteria

Troubleshooting

  • Authentication error with GMail - "Application-specific password required"

    See: https://support.google.com/mail/answer/185833?hl=en

  • More secure apps (XOAUTH2 protocol) - Use the OAuth2 flow as in this Portal robot:

    example-oauth-email

    Make sure to specify a provider (and optionally a tenant) when importing the library and planning to use this flow.

Examples

Robot Framework

It is highly recommended to secure your passwords and take care that they are not stored in version control by mistake. See RPA.Robocorp.Vault to see how to store secrets in Robocorp Vault.

When sending HTML content with IMG tags, the src filenames must match the base image name given with the images parameter.

*** Settings *** Library RPA.Email.ImapSmtp smtp_server=smtp.gmail.com smtp_port=587 Task Setup Authorize account=${GMAIL_ACCOUNT} password=${GMAIL_PASSWORD} *** Variables *** ${GMAIL_ACCOUNT} ACCOUNT_NAME ${GMAIL_PASSWORD} APP_PASSWORD ${RECIPIENT_ADDRESS} RECIPIENT ${BODY_IMG1} ${IMAGEDIR}${/}approved.png ${BODY_IMG2} ${IMAGEDIR}${/}invoice.png ${EMAIL_BODY} <h1>Heading</h1><p>Status: <img src='approved.png' alt='approved image'/></p> ... <p>INVOICE: <img src='invoice.png' alt='invoice image'/></p> *** Tasks *** Sending email Send Message sender=${GMAIL_ACCOUNT} ... recipients=${RECIPIENT_ADDRESS} ... subject=Message from RPA Robot ... body=RPA Robot message body Sending HTML Email With Image [Documentation] Sending email with HTML content and attachment Send Message ... sender=${GMAIL_ACCOUNT} ... recipients=${RECIPIENT_ADDRESS} ... subject=HTML email with body images (2) plus one attachment ... body=${EMAIL_BODY} ... html=${TRUE} ... images=${BODY_IMG1}, ${BODY_IMG2} ... attachments=example.png

Python

from RPA.Email.ImapSmtp import ImapSmtp gmail_account = "ACCOUNT_NAME" gmail_password = "APP_PASSWORD" mail = ImapSmtp(smtp_server="smtp.gmail.com", smtp_port=587) mail.authorize(account=gmail_account, password=gmail_password) mail.send_message( sender=gmail_account, recipients="RECIPIENT", subject="Message from RPA Python", body="RPA Python message body", )

Importing

Initialize self. See help(type(self)) for accurate signature.