mailer
Module#
agent |
description |
---|---|
sendmail |
(linux-only) uses either /usr/lib/sendmail or /usr/bin/mail |
SMTP |
uses smtplib [1] |
TESTING THE CONFIGURATION#
It is possible to test the email sending using the configuration file. (Alternatively, the GUI has a File menu item to send a test email.) First, the help message for the command:
$ pvMail_mail_test --help
usage: pvMail_mail_test [-h] recipient [recipient ...]
test the email sender from PvMail 3.1.0
positional arguments:
recipient email address(es), whitespace-separated if more than one
optional arguments:
-h, --help show this help message and exit
To test the email sending using the configuration file:
$ python ./mailer.py joeuser@example.com
An email message is sent from joeuser to joeuser@example.com:
1To: joeuser@example.com
2Subject: PvMail mailer test message: sendmail
3Date: Tue, 16 Aug 2024 13:17:31 -0600 (CDT)
4From: joeuser@example.com
5
6This is a test of the PvMail mailer, v4.0.0
7For more help, see: https://BCDA-APS.github.io/pvMail
Source Code Documentation#
Send a message by email to one or more recipients (by SMTP or sendmail).
- PvMail.mailer.sendMail_SMTP(subject, message, recipients, smtp_cfg, sender=None, logger=None)[source]#
send email message through SMTP server
- Parameters:
subject (str) – short text for email subject
message (str) – full text of email body
recipients ([str]) – list of email addresses to receive the message
smtp_cfg (dict) –
such as returned from
PvMail.ini_config.Config.get
- server:
required - (str) SMTP server
- user:
required - (str) username to login to SMTP server
- port:
optional - (str) SMTP port
- password:
optional - (str) password for username
- connection_security:
optional - (str) STARTTLS (the only choice, if specified)
sender (str) – “From” address, if None use smtp_cfg[‘user’] value
EXAMPLE:
>>> import PvMail.ini_config >>> smtp_cfg = PvMail.ini_config.Config().get() >>> recipients = ['joe@gmail.com', 'sally@example.org'] >>> subject = 'SMTP test message' >>> message = PvMail.ini_config.__doc__ >>> sendMail_SMTP(subject, message, recipients, smtp_cfg)
- PvMail.mailer.sendMail_sendmail(subject, message, recipients, sendmail_cfg, sender=None, logger=None)[source]#
Send an email message using sendmail (linux only).
- Parameters:
subject (str) – short text for email subject
message (str) – full text of email body
recipients ([str]) – list of email addresses to receive the message
sendmail_cfg (dict) –
such as returned from
PvMail.ini_config.Config.get
- user:
required - (str) username to for sendmail (or similar) program
sender (str) – “From” address, if None use smtp_cfg[‘user’] value
logger (obj) – optional message logging method
EXAMPLE:
>>> import PvMail.ini_config >>> sendmail_cfg = PvMail.ini_config.Config().get() >>> recipients = ['joe@gmail.com', 'sally@example.org'] >>> subject = 'sendmail test message' >>> message = PvMail.ini_config.__doc__ >>> sendMail_sendmail(subject, message, recipients, sendmail_cfg)
- PvMail.mailer.send_message(subject, message, recipients, config)[source]#
send an email message
- Parameters:
subject (str) – short text for email subject
message (str) – full text of email body
recipients ([str]) – list of email addresses to receive the message
config (dict) – such as returned from
PvMail.ini_config.Config