Comments (3)
It looks like this will require parsing the CC and BCC fields and adding those addresses to the send_email()
function call.
https://www.blog.pythonlibrary.org/2013/06/26/python-102-how-to-send-an-email-using-smtplib-email/
from mailmerge.
This seems to work for me. It's untested in python 3 but hopefully works there too.
--- api.py 2017-07-13 17:01:50.000000000 +0100
+++ /Users/rupert/code/mailmerge/mailmerge/api.py 2017-07-15 11:08:07.000000000 +0100
@@ -11,6 +11,7 @@
import sys
import smtplib
import email.parser
+import email.utils
import configparser
import getpass
import csv
@@ -23,6 +24,22 @@
CONFIG_FILENAME_DEFAULT = "mailmerge_server.conf"
+def parsemail(text):
+ """Parse message headers, then remove BCC header."""
+ message = email.parser.Parser().parsestr(text)
+ addrs = email.utils.getaddresses(message.get_all("to", [])) + \
+ email.utils.getaddresses(message.get_all("cc", [])) + \
+ email.utils.getaddresses(message.get_all("bcc", []))
+ recipients = [x[1] for x in addrs]
+ message.__delitem__("bcc")
+
+ for recipient in recipients:
+ print("RCPT TO:<" + recipient + ">")
+ print(message.as_string())
+
+ return (message,recipients)
+
+
def sendmail(text, config_filename):
"""Send email message using Python SMTP library."""
# Read config file from disk to get SMTP server host, port, username
@@ -46,8 +63,7 @@
sendmail.host)
sendmail.password = getpass.getpass(prompt)
- # Parse message headers
- message = email.parser.Parser().parsestr(text)
+ (message,recipients)=parsemail(text)
# Connect to SMTP server
if sendmail.security == "SSL/TLS":
@@ -69,12 +85,12 @@
# Send message
try:
# Python 3.x
- smtp.send_message(message)
+ smtp.send_message(message, recipients)
except AttributeError:
# Python 2.7.x
smtp.sendmail(
message["from"],
- message["to"],
+ recipients,
message.as_string(),
)
smtp.close()
@@ -200,10 +216,10 @@
# Fill in template fields using fields from row of CSV file
message = template.render(**row)
- print(message)
# Send message
if dry_run:
+ parsemail(message)
print(">>> sent message {} DRY RUN".format(i))
else:
sendmail(message, config_filename)
from mailmerge.
Thanks for the patch! I'll integrate and test this soon.
from mailmerge.
Related Issues (20)
- Recipe for machine-readable messages
- FEATURE MISSING: personal attachments HOT 2
- Block list HOT 1
- Apple Mail with attachments issue (former title: UTF-8 support issue) HOT 11
- Move test dependecies to extras_require
- Debug flag
- mails limit per mail feature HOT 5
- Interactive mode
- Drop Python 2 Support HOT 5
- Change CI to GitHub Actions
- setup.py has "html5" but It has a new name "html5lib"
- Inline images not working in thunderbird? HOT 5
- Crashes on email adresses with illegal characters HOT 2
- Replace `setup.py` with `pyproject.toml`
- Support CSV files with semicolons as separators HOT 3
- Add support for 2FA OAuth authentication HOT 2
- New release on Pipy HOT 1
- No mailmerge_server.conf file in the repository HOT 2
- Load system default SSL cert
- Space at the end of the header row
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mailmerge.