tomekwojcik / envelopes Goto Github PK
View Code? Open in Web Editor NEWMailing for human beings
Home Page: http://tomekwojcik.github.io/envelopes/
License: MIT License
Mailing for human beings
Home Page: http://tomekwojcik.github.io/envelopes/
License: MIT License
This can be made even more humanistic by using to
and from
instead of to_addr
and from_addr
since "address" is usually implied when talking about email.
You could then allow to
to accept a list as well as a single string without having to add another argument.
I am not sure if this deserves an Issue and you can close it if you feel so, I will not complain :)
The fact is I made my report class using your excellent Envelope library (not subclassing) and I wanted to pass connection arguments as a dictionary from a class attribute. Then I see that host is not a kwarg, it feels "odd" is the only one, do you agree?
Cheers.
I've tried with 3 different SMTP providers: gmail.com, smtp.com and fastmail.fm and none of their published settings are sending messages, so I thought I'd ping.
Modify the code to target CPython versions: 2.6, 2.7, 3.3.
The thing is simple - make to_addr
and from_addr
accept lists in addition to single addresses. And nuke the from_name
and to_name
Envelopes.init() args.
path = args.pathname
if path:
if path.is_dir():
# compress the folder before submitting
# compressed file is named by subject
compath = path.parent / (args.subject+".7z")
subprocess.run(["7z", "a", "-t7z", compath, path])
envelope.add_attachment(str(compath))
elif path.is_file():
envelope.add_attachment(str(path))
envelope.send(...)
print('The email is sent to ...')
if path.is_dir(): # delete the compressed file finally
os.remove(compath)
I am trying to attach an HTML file to an email.
I get the following error:
/usr/local/lib/python2.7/email/message.pyc in get(self, name, failobj)
358 is missing.
359 """
--> 360 name = name.lower()
361 for k, v in self._headers:
362 if k.lower() == name:
AttributeError: 'slice' object has no attribute 'lower'
Stepping into the code with ipython debugger it seems that it detects the MIME type of the file, correctly, as text/html
but this causes it to follow a different codepath which is where it fails: https://github.com/tomekwojcik/envelopes/blob/master/envelopes/envelope.py#L292
If I force it to use a generic mime type instead:
envelope.add_attachment("myfile.html", mimetype="application/octet-stream")
...then I can send the message but something weird happens - Gmail shows the message as having the file attached twice, even though if I go back and check the envelope
object it seems I have only one attachment:
In [18]: envelope._parts
Out[18]:
[('text/plain', 'my body text', 'utf-8'),
('application/octet-stream',
<email.mime.base.MIMEBase instance at 0x270cd40>)]
It'd be great if envelopes supported OAuth authentication to e.g. gmail (https://developers.google.com/accounts/docs/OAuth2) with a minimum of configuration, because that's a pain to figure out. :)
Images and other local resources could be automagically attached to the Envelope. Alternatively the file://
URLs could be replaced with data URIs.
according to the docs:
Envelopes has been developed and tested with Python 2.7. Currently, Envelopes supports Python 2.6, 2.7 and 3.3.
Most people upgraded to Python3 these days. I guess above line needs an upgrade. Python 3.3 is dated.
add_attech method with file’s suffix like '.txt' will be called something like this
File "/usr/lib/python2.6/site-packages/envelopes/envelope.py", line 329, in send
send_result = conn.send(self)
File "/usr/lib/python2.6/site-packages/envelopes/conn.py", line 87, in send
msg = envelope.to_mime_message()
File "/usr/lib/python2.6/site-packages/envelopes/envelope.py", line 292, in to_mime_message
msg.attach(MIMEText(part[1], type_min, self._charset))
File "/usr/lib64/python2.6/email/mime/text.py", line 30, in init
self.set_payload(_text, _charset)
File "/usr/lib64/python2.6/email/message.py", line 224, in set_payload
self.set_charset(charset)
File "/usr/lib64/python2.6/email/message.py", line 268, in set_charset
self._payload = charset.body_encode(self._payload)
File "/usr/lib64/python2.6/email/charset.py", line 387, in body_encode
return email.base64mime.body_encode(s)
File "/usr/lib64/python2.6/email/base64mime.py", line 147, in encode
enc = b2a_base64(s[i:i + max_unencoded])
File "/usr/lib64/python2.6/email/message.py", line 292, in getitem
return self.get(name)
File "/usr/lib64/python2.6/email/message.py", line 358, in get
name = name.lower()
AttributeError: 'slice' object has no attribute 'lower'
other suffix seems ok.
I can see that there is no more development happening here since 2014. On the other hand, @vamega has an active fork.
Is there any plan to merge?
How about pushing vamega's changes to pypi? It contains a BIG feature (attaching from streams instead of files).
I use envelopes in our project.
I found a bug:some attachment disappear in some email client (Airmail exactly)when I send email use envelopes.
I try to fix this bug,and I realize the following source is origin
https://github.com/tomekwojcik/envelopes/blob/master/envelopes%2Fenvelope.py#L276
msg = MIMEMultipart('alternative')
I inherit envelopes class and rewrite to_mime_message() function,then bug fixed
msg = MIMEMultipart('mixed')
RFC 1341 7.2.3 say:
The multipart/alternative type is syntactically identical to multipart/mixed, but the semantics are different. In particular, each of the parts is an "alternative" version of the same information. User agents should recognize that the content of the various parts are interchangeable. The user agent should either choose the "best" type based on the user's environment and preferences, or offer the user the available alternatives. In general, choosing the best type means displaying only the LAST part that can be displayed.
So why envelopes project use multipart/alternative
type instead multipart/mixed
?Is it a bug?
Sometimes I have a file in-memory, not saved to disk, and I'd like to add it as an attachment.
Currently add_attachment
only works on files that are saved to the filesystem.
Please allow attaching files that are in-memory.
I want to send html_body with image src .
html_body=u'<html><body><h1>Hello</h1><p><img src="cid:screenshot.png"></p></body></html>'
use src="cid:screenshot.png" I need to add a image attachment:
envelope.add_attachment(r'D:\XXX\screenshot.png')
and I need add a header ('Content-ID', ‘screenshot.png’) to this attachment.
but I don't konw how to add attachment's headers in envelopes.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.