Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Sending email with Python
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  11 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Ram Rachum  
View profile  
 More options Jun 30 2012, 11:58 am
From: Ram Rachum <r...@rachum.com>
Date: Sat, 30 Jun 2012 18:58:10 +0300
Local: Sat, Jun 30 2012 11:58 am
Subject: Sending email with Python

Hi everyone,

Is there a package that is to email what `requests` is to HTTP?

Thanks,
Ram.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
oz katz  
View profile  
 More options Jun 30 2012, 12:11 pm
From: oz katz <ozkatz...@gmail.com>
Date: Sat, 30 Jun 2012 19:11:54 +0300
Local: Sat, Jun 30 2012 12:11 pm
Subject: Re: [pyweb-il:3546] Sending email with Python

What exactly are your needs?

There is
https://github.com/kennethreitz/inbox.py

(from the author of "requests")
But again, you should probably be more specific..

Oz


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ram Rachum  
View profile  
 More options Jun 30 2012, 3:05 pm
From: Ram Rachum <r...@rachum.com>
Date: Sat, 30 Jun 2012 22:05:00 +0300
Subject: Re: [pyweb-il:3547] Sending email with Python

Thanks Oz. It's good to know about inbox.py, but that doesn't help here;
I'm interested in sending emails, not receiving them.

I basically want a function `send_mail` that takes an email address, a
subject line, and a content, and sends.

I know that Django provides one, but using Django would entail having a
"site" and a settings file, and I don't want any of those for this project.

Look at the first example here:

http://docs.python.org/library/email-examples.html#email-examples

Under "First, let’s see how to create and send a simple text message"

I don't know whether this should be considered sad or funny. That example
code does everything except licking a stamp in order to put it on the
email. This is the exact opposite of what I'm looking for :)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Shai Berger  
View profile  
 More options Jun 30 2012, 4:05 pm
From: Shai Berger <s...@platonix.com>
Date: Sat, 30 Jun 2012 23:05:48 +0300
Local: Sat, Jun 30 2012 4:05 pm
Subject: Re: [pyweb-il:3548] Sending email with Python
On Saturday 30 June 2012, Ram Rachum wrote:

> I basically want a function `send_mail` that takes an email address, a
> subject line, and a content, and sends.

email doesn't work this way. You need a sender, and most mail servers for
receivers will not talk to you if you don't have an MX record in DNS; which
means, in practice, you need some "recognized" mail server to send through.

So, your "send mail" function can only work after you've told it, in some way,
who's the sender, where's the mail server, and (usually) how to log in to it.

> I know that Django provides one, but using Django would entail having a
> "site" and a settings file, and I don't want any of those for this project.

The little email I did out of Django was using Lamson (lamsonproject.org) --
but again, that is more on the receiving end, and it's a whole framework.
Perhaps you can get something more to your taste out of that.

HTH,
        Shai.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ram Rachum  
View profile  
 More options Jun 30 2012, 4:15 pm
From: Ram Rachum <r...@rachum.com>
Date: Sat, 30 Jun 2012 23:15:52 +0300
Local: Sat, Jun 30 2012 4:15 pm
Subject: Re: [pyweb-il:3549] Sending email with Python

Sorry, I should have specified that I'm okay with specifying SMTP settings.
So: Import, specify STMP settings, send mail. Anything that does that?

Basically my approach is "simple things should be simple, complex things
should be possible." I want a package that makes the basic tasks as simple
as possible, without even having to read the documentation beyond the
"quick examples" section, and people who have more complex needs could dig
in to the documentation and the code, instantiate classes and call their
methods, etc.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Yuval Adam  
View profile  
 More options Jun 30 2012, 5:31 pm
From: Yuval Adam <yuv....@gmail.com>
Date: Sun, 1 Jul 2012 00:31:46 +0300
Local: Sat, Jun 30 2012 5:31 pm
Subject: Re: [pyweb-il:3550] Sending email with Python

> Sorry, I should have specified that I'm okay with specifying SMTP
> settings. So: Import, specify STMP settings, send mail. Anything that does
> that?

Yeah, the Django builtin send_mail(). I'm not sure why you think it's
complicated.

Basic Settings (Google as example):

EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'f...@example.com'
EMAIL_HOST_PASSWORD = 'secretPASS'
EMAIL_PORT = 587
EMAIL_USE_TLS = True

And then it's just:

send_mail('subject', 'content', 'f...@example.com', ['...@example.com'])

That's it. What's all the fuss about?

--
Yuval Adam
http://y3xz.com


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ram Rachum  
View profile  
 More options Jun 30 2012, 5:52 pm
From: Ram Rachum <r...@rachum.com>
Date: Sun, 1 Jul 2012 00:52:45 +0300
Local: Sat, Jun 30 2012 5:52 pm
Subject: Re: [pyweb-il:3551] Sending email with Python

It's almost good enough, the problem is that you need to have a Django
settings file.

Let me give you an example of usage, of something I wanted to do today.

Today, as many of you have probably noticed, half the Internet was down due
to electrical storms in the East Coast. Okay, not really half, but many big
sites. (Heroku, AWS, Pinterest, NetFlix...)

Our website was one of the casualties. It was down, and I wanted to write a
short Python script that would try to visit it every 2 minutes, and when it
finally succeeds, shoot me a mail telling me the site is back up.

Now, that script is so simple, I intended to write it in the REPL, not even
saving it to a file, and just keep it running in a `screen` session.

I wanted something to the effect of:

>>> while 'Error' in requests.get('http://oursite.com').content:

...     time.sleep(120)
... send_mail('...@rachum.com', 'Site is back up!')

Now, if I had to introduce a Django `settings.py` file into this, it would
have been a lot more cumbersome.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Yuval Adam  
View profile  
 More options Jun 30 2012, 6:06 pm
From: Yuval Adam <yuv....@gmail.com>
Date: Sun, 1 Jul 2012 01:06:09 +0300
Local: Sat, Jun 30 2012 6:06 pm
Subject: Re: [pyweb-il:3552] Sending email with Python

Well, as far as I remember the smtplib API is reasonable.
Something along the lines:

import smtplib
smtp = smtplib.SMTP('server', 'some', 'other', 'conn', 'params')
smtp.sendmail('subject', 'content', 'to', 'from')

Don't copy-paste, obviously, but real use shouldn't be much different.

Though I definitely agree it would be nice to see an SMTP equivalent for
requests.

--
Yuval Adam
http://y3xz.com

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ram Rachum  
View profile  
 More options Jun 30 2012, 6:23 pm
From: Ram Rachum <r...@rachum.com>
Date: Sun, 1 Jul 2012 01:23:21 +0300
Local: Sat, Jun 30 2012 6:23 pm
Subject: Re: [pyweb-il:3553] Sending email with Python

I was almost convinced that `smtplib` is good enough, but then I saw the
example here:

http://docs.python.org/library/smtplib.html#smtp-example

Ignore the `raw_input` parts which take the bulk of the example, but look
at the construction of `msg`. You have to add the `From` and `To` headers
manually in the text. Lame.

And actually a bigger issue: You need to authenticate to the SMTP server,
and that's a separate line, calling `SMTP.login`.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ram Rachum  
View profile  
 More options Jul 4 2012, 4:26 am
From: Ram Rachum <r...@rachum.com>
Date: Wed, 4 Jul 2012 11:26:10 +0300
Local: Wed, Jul 4 2012 4:26 am
Subject: Re: [pyweb-il:3553] Sending email with Python

Attached is the makeshift module I made for myself now. It's very very
basic. This way I could send email to myself in simple scripts.

To use it, replace 'your.auxiliary.em...@gmail.com', 'your.auxiliary.password'
and 'your.r...@email.com' with real values.

Hope this is useful for someone.

  lame_smtp.py
< 1K Download

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ori Peleg  
View profile  
 More options Jul 4 2012, 5:08 am
From: Ori Peleg <ori...@gmail.com>
Date: Wed, 4 Jul 2012 12:08:01 +0300
Local: Wed, Jul 4 2012 5:08 am
Subject: Re: [pyweb-il:3555] Sending email with Python

I also think smtplib is great, it's what I'd use for simply sending emails
to an upstream SMTP server.

If you want more intelligent email processing, Zed Shaw's Lamson is really
cool: http://lamsonproject.org/

--
Check out my blog: http://orip.org

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »