bradwhittington / django-mailgun Goto Github PK
View Code? Open in Web Editor NEWThis project is deprecated in favor of https://github.com/anymail/django-anymail
License: MIT License
This project is deprecated in favor of https://github.com/anymail/django-anymail
License: MIT License
It would have saved me a few hours of troubleshooting what I thought was my problem...
an error
in 92, lost a ')'
Not dissimilar to #9, we are going to try using Mailgun's email encoding:
#....
clean_all = lambda addrs: [sanitize_address(addr, email_message.encoding) for addr in addrs]
from_email = sanitize_address(email_message.from_email, email_message.encoding)
text = None
html = None
if email_message.content_subtype == 'plain':
text = email_message.body
if email_message.content_subtype == 'html':
html = email_message.body
if isinstance(email_message, EmailMultiAlternatives):
for body, mime in email_message.alternatives:
if mime == 'text/html':
html = body
try:
r = requests.post(
url=self._api_url + 'messages',
auth=('api', self._access_key),
data={
'from': from_email,
'to': clean_all(email_message.to),
'cc': clean_all(email_message.cc),
'bcc': clean_all(email_message.bcc),
'subject': email_message.subject,
'text': text,
'html': html,
},
files=[
('attachment', (filename, content))
for filename, content, mimetype in [
attachment for attachment in email_message.attachments
if isinstance(attachment, tuple)
]
]
)
#....
Happy to get a PR going if you think that might be useful. It isn't complete yet.
django-mailgun
should allow sending arbitrary headers to Mailgun, especially to support their custom headers, as documented in https://documentation.mailgun.com/en/latest/api-sending.html#sending.
For example, how do I disable click-tracking for a specific email?
Mailgun has a feature to schedule delivery of messages at a given date and time. All is needed is to pass an extra parameter to the Mailgun API call with the date.
That would be a nice to have, but could become quite a chunk as it would possibly need:
send_scheduled_mail
wrapperScheduledEmailMessage
with delivery_date
attribute (don't think monkey-patching a non-standard attribute on Django's EmailMessage
is a clean solution)MailgunBackend._send
to add this attribute to the API call with the correct format only if it's present in the email_message
Happy to implement it if agreed.
I used pip install django-mailgun to add the app to my Django project.
It seems the code in pip is not synced with github.
try:
from cStringIO import StringIO
except ImportError:
from StringIO import StringIO
I see here that the URL suffix would need to change and an "html" field added to the data (based on Mailgun's documentation).
Update the code to use the latest api.
I wanted to do a new release. Alas, Python 3 is broken - I should have run tests on all versions of Python before accepting pull requests . For that matter, I should have set up continuous integration. This needs to be fixed before I'll issue a release.
Problem: I simply don't have the free time to support a library for a commercial endeavor (@mailgun).
If someone can get the tests working properly for Python 2.7 and Python 3.5 I'll issue a release.In the meantime, the project is on hold.
https://pypi.org/project/django-mailgun/ is returning 404, so I can't install django-mailgun, anybody deleted it?
Means we'll be more current with features.
Backend should support the CC and BCC headers http://documentation.mailgun.net/quickstart.html
Hence the step pip install -e git://github.com/mailgun/mailgun.py.git#egg=pymailgun
does not work.
EU customer get a different server to connecto to -> api.eu.mailgun.net
So we would need an option for this.
Preferably py.test, but django unittests work too.
When i want to send an html only message without a text part, django mailgun send the whole message as text, not as html.
I fixed it in my fork, let me know if u think its a valid issue then i`l create a pull request.
An email message with alternative is built like so:
email_message = EmailMultiAlternatives(subject, body, from_email, [to_email])
email_message.attach_alternative(foo, 'text/html')
email_message.mixed_subtype = 'related'
email_message.attach(MIMEImage(image_fp.read()))
email_message.content_subtype = "html"
email_message.send()
When sent via mailgun the following error is given:
AttributeError("'int' object has no attribute 'lower'",)
Traceback (most recent call last):
File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/core/mail/message.py
", line 303, in send
return self.get_connection(fail_silently).send_messages([self])
File "/opt/python/run/venv/local/lib/python2.7/site-packages/django_mailgun.py", line 16
8, in send_messages
if self._send(message):
File "/opt/python/run/venv/local/lib/python2.7/site-packages/django_mailgun.py", line 13
7, in _send
post_data.append(('attachment', (attachment[0], attachment[1],)))
File "/usr/lib64/python2.7/email/message.py", line 294, in __getitem__
return self.get(name)
File "/usr/lib64/python2.7/email/message.py", line 360, in get
name = name.lower()
AttributeError: 'int' object has no attribute 'lower'
The Django attach()
API accepts both MIMEBase parameters as well as (filename, content, mimetype)
triplets and it seems django-mailgun doesn't support the former.
Hi,
I just following your readme, but I keep getting this error :
This is my setting (I'm not sure, whether I should using secret key or public key, but both is error when I'm trying to send email) :
EMAIL_BACKEND = 'django_mailgun.MailgunBackend'
MAILGUN_ACCESS_KEY = 'key-06b1d48a5805393c825ceefa054bXXXX'
MAILGUN_SERVER_NAME = 'sandboxfa1f6fe021044f319c639f9da08eXXXX.mailgun.org'
My views.py :
def order_form(request):
if request.method == "POST":
form = OrderForm(request.POST, request.FILES)
if form.is_valid():
order = form.save(commit=False)
order.tanggal_order = datetime.datetime.now()
order.save()
subject = "NEW ZEGUYO ORDER"
to = [order.email, '[email protected]', '[email protected]']
from_email = '[email protected]'
ctx = {
'nama': order.nama,
'id_order': order.id,
}
message = get_template('email/order_email.html').render(Context(ctx))
msg = EmailMessage(subject, message, to=to, from_email=from_email)
msg.content_subtype = 'html'
msg.send()
return render(request, 'order_app/order_success.html')
else:
form = OrderForm()
return render(request, 'order_app/order_form.html', {'form': form})
I'm using django 1.9.2, Python 2.7
Did I miss something here?
Thank you in advance for any help you can provide :)
Regards,
I see that the master branch of django-mailgun has support for python3 because it uses the io
module instead of the StringIO
module, but this change is not reflected in the newest version of django mailgun on PyPi.
Since "All text is Unicode" in Python v>3.0 then this line of code will throw an error says:
name 'unicode' is not defined
So, regarding to this answer, I guess unicode
function should be changed to str
or decode()
The wheel package of the latest version on pypi (https://pypi.python.org/packages/2.7/d/django-mailgun/django_mailgun-0.7.0-py2.py3-none-any.whl#md5=f9f840324bee50550cfe4278ad29b5e1) has an init.py that contains an older version of django-mailgun. When our app tries to send emails, Django uses this version of the backend which has none of the latest changes, and not the updated version of the code in django_mailgun.py. Removing the init file solves the issue, as then Django uses django_mailgun.py.
Using Django 1.8.4, django-mailgun 0.7.0
I see on Pip that django-mailgun is up to 2.2, but your github tags only go up to 2.1.
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.