Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #61788 > unrolled thread

Using pythons smtp server

Started byVincent Davis <vincent@vincentdavis.net>
First post2013-12-12 18:01 -0700
Last post2013-12-14 12:59 -0500
Articles 10 — 5 participants

Back to article view | Back to comp.lang.python


Contents

  Using pythons smtp server Vincent Davis <vincent@vincentdavis.net> - 2013-12-12 18:01 -0700
    Re: Using pythons smtp server Grant Edwards <invalid@invalid.invalid> - 2013-12-13 16:40 +0000
      Re: Using pythons smtp server Vincent Davis <vincent@vincentdavis.net> - 2013-12-13 10:13 -0700
      Re: Using pythons smtp server Chris Angelico <rosuav@gmail.com> - 2013-12-14 05:15 +1100
      Re: Using pythons smtp server Vincent Davis <vincent@vincentdavis.net> - 2013-12-13 11:27 -0700
        Re: Using pythons smtp server Grant Edwards <invalid@invalid.invalid> - 2013-12-13 20:33 +0000
      Re: Using pythons smtp server Chris Angelico <rosuav@gmail.com> - 2013-12-14 05:29 +1100
      Re: Using pythons smtp server Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-12-13 19:46 -0500
        Re: Using pythons smtp server Irmen de Jong <irmen.NOSPAM@xs4all.nl> - 2013-12-14 16:48 +0100
          Re: Using pythons smtp server Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-12-14 12:59 -0500

#61788 — Using pythons smtp server

FromVincent Davis <vincent@vincentdavis.net>
Date2013-12-12 18:01 -0700
SubjectUsing pythons smtp server
Message-ID<mailman.4046.1386908855.18130.python-list@python.org>

[Multipart message — attachments visible in raw view] — view raw

I have an app that generates a file one a day and would like to email it
using pythons SMTP server.
http://docs.python.org/2/library/smtpd.html#smtpd.SMTPServer
The documentation is kinda sparse and I cant seem to find any good examples.

Basically what I want to do; when my app runs it would initiate a SMTP
server, send the attachment and shutdown the SMTP after.

Vincent Davis

[toc] | [next] | [standalone]


#61834

FromGrant Edwards <invalid@invalid.invalid>
Date2013-12-13 16:40 +0000
Message-ID<l8fd9s$ssb$1@reader1.panix.com>
In reply to#61788
On 2013-12-13, Vincent Davis <vincent@vincentdavis.net> wrote:

> I have an app that generates a file one a day and would like to email it
> using pythons SMTP server.

You don't send mail using an SMTP server.  You receive mail using an
SMTP server.

> http://docs.python.org/2/library/smtpd.html#smtpd.SMTPServer
> The documentation is kinda sparse and I cant seem to find any good examples.
>
> Basically what I want to do; when my app runs it would initiate a SMTP
> server, send the attachment and shutdown the SMTP after.

Newsgroups: comp.lang.python
From: Grant Edwards <invalid@invalid.invalid>
Subject: Re: Using pythons smtp server
References: <mailman.4046.1386908855.18130.python-list@python.org>
Followup-To:

On 2013-12-13, Vincent Davis <vincent@vincentdavis.net> wrote:

> I have an app that generates a file one a day and would like to email
> it using pythons SMTP server.

You don't send mail using an SMTP server.  You receive mail using an 
SMTP server.  You send mail using an SMTP client.

> http://docs.python.org/2/library/smtpd.html#smtpd.SMTPServer
> The documentation is kinda sparse and I cant seem to find any good examples.
>
> Basically what I want to do; when my app runs it would initiate a SMTP
> server, send the attachment and shutdown the SMTP after.

https://www.google.com/search?q=python+send+email+smtp

-- 
Grant Edwards               grant.b.edwards        Yow! The PINK SOCKS were
                                  at               ORIGINALLY from 1952!!
                              gmail.com            But they went to MARS
                                                   around 1953!!

[toc] | [prev] | [next] | [standalone]


#61852

FromVincent Davis <vincent@vincentdavis.net>
Date2013-12-13 10:13 -0700
Message-ID<mailman.4087.1386957801.18130.python-list@python.org>
In reply to#61834

[Multipart message — attachments visible in raw view] — view raw

>
> "You don't send mail using an SMTP server.  You receive mail using an
> SMTP server.
> ​"​
>

Um maybe, I guess it is a matter of perspective.

Let me rephrase my question. ​​I want to send an email using python but do
not want to use an external service. Does python have the ability to send
emails without installing additional software or using an external
server/service?
Maybe I am wrong, I thought examples like s = smtplib.SMTP('localhost')
​​ are using a local(outside of python) smtp server, like postfix.




Vincent Davis
720-301-3003


On Fri, Dec 13, 2013 at 9:40 AM, Grant Edwards <invalid@invalid.invalid>wrote:

> On 2013-12-13, Vincent Davis <vincent@vincentdavis.net> wrote:
>
> > I have an app that generates a file one a day and would like to email it
> > using pythons SMTP server.
>
> You don't send mail using an SMTP server.  You receive mail using an
> SMTP server.
>
> > http://docs.python.org/2/library/smtpd.html#smtpd.SMTPServer
> > The documentation is kinda sparse and I cant seem to find any good
> examples.
> >
> > Basically what I want to do; when my app runs it would initiate a SMTP
> > server, send the attachment and shutdown the SMTP after.
>
> Newsgroups: comp.lang.python
> From: Grant Edwards <invalid@invalid.invalid>
> Subject: Re: Using pythons smtp server
> References: <mailman.4046.1386908855.18130.python-list@python.org>
> Followup-To:
>
> On 2013-12-13, Vincent Davis <vincent@vincentdavis.net> wrote:
>
> > I have an app that generates a file one a day and would like to email
> > it using pythons SMTP server.
>
> You don't send mail using an SMTP server.  You receive mail using an
> SMTP server.  You send mail using an SMTP client.
>
> > http://docs.python.org/2/library/smtpd.html#smtpd.SMTPServer
> > The documentation is kinda sparse and I cant seem to find any good
> examples.
> >
> > Basically what I want to do; when my app runs it would initiate a SMTP
> > server, send the attachment and shutdown the SMTP after.
>
> https://www.google.com/search?q=python+send+email+smtp
>
> --
> Grant Edwards               grant.b.edwards        Yow! The PINK SOCKS were
>                                   at               ORIGINALLY from 1952!!
>                               gmail.com            But they went to MARS
>                                                    around 1953!!
> --
> https://mail.python.org/mailman/listinfo/python-list
>

[toc] | [prev] | [next] | [standalone]


#61857

FromChris Angelico <rosuav@gmail.com>
Date2013-12-14 05:15 +1100
Message-ID<mailman.4090.1386958559.18130.python-list@python.org>
In reply to#61834
On Sat, Dec 14, 2013 at 4:13 AM, Vincent Davis <vincent@vincentdavis.net> wrote:
> Let me rephrase my question. I want to send an email using python but do not
> want to use an external service. Does python have the ability to send emails
> without installing additional software or using an external server/service?

Any SMTP server you install has to do one of three things with the
mail you give it:

1) Accept it locally. Presumably the wrong thing to do here.
2) Deliver it to the authoritative SMTP server for the domain.
3) Deliver it to an intermediate server.

(Edit: Your next mail shows that you understand that, as looking up
the MX record is what I was going to say here.)

So if you want to avoid using an external intermediate server, you
need to find and talk to the authoritative server. Now, this is where
another big consideration comes in. What envelope From address are you
going to use? Is your own IP address allowed to send mail for that
domain? If not, you may be forced to use the legitimate server for
that domain. There are other concerns, too; if you don't have a nice
name to announce in the HELO, you might find your mail treated as
spam. But if you deal with all that, then yes, the only thing you need
to do is look up the MX record and pick the best server. (And then
deal with other concerns like coping with that one being down, which
is the advantage of having a local mail queue. But sometimes that
doesn't matter, like if you're sending to yourself for notifications.)

ChrisA

[toc] | [prev] | [next] | [standalone]


#61858

FromVincent Davis <vincent@vincentdavis.net>
Date2013-12-13 11:27 -0700
Message-ID<mailman.4091.1386959243.18130.python-list@python.org>
In reply to#61834

[Multipart message — attachments visible in raw view] — view raw

Grant, Chris
Thanks !!!
I guess in the end this is a bad idea, (for my purposes) I should just use
my gmail account smtp server.

Vincent Davis
720-301-3003


On Fri, Dec 13, 2013 at 11:15 AM, Chris Angelico <rosuav@gmail.com> wrote:

> On Sat, Dec 14, 2013 at 4:13 AM, Vincent Davis <vincent@vincentdavis.net>
> wrote:
> > Let me rephrase my question. I want to send an email using python but do
> not
> > want to use an external service. Does python have the ability to send
> emails
> > without installing additional software or using an external
> server/service?
>
> Any SMTP server you install has to do one of three things with the
> mail you give it:
>
> 1) Accept it locally. Presumably the wrong thing to do here.
> 2) Deliver it to the authoritative SMTP server for the domain.
> 3) Deliver it to an intermediate server.
>
> (Edit: Your next mail shows that you understand that, as looking up
> the MX record is what I was going to say here.)
>
> So if you want to avoid using an external intermediate server, you
> need to find and talk to the authoritative server. Now, this is where
> another big consideration comes in. What envelope From address are you
> going to use? Is your own IP address allowed to send mail for that
> domain? If not, you may be forced to use the legitimate server for
> that domain. There are other concerns, too; if you don't have a nice
> name to announce in the HELO, you might find your mail treated as
> spam. But if you deal with all that, then yes, the only thing you need
> to do is look up the MX record and pick the best server. (And then
> deal with other concerns like coping with that one being down, which
> is the advantage of having a local mail queue. But sometimes that
> doesn't matter, like if you're sending to yourself for notifications.)
>
> ChrisA
> --
> https://mail.python.org/mailman/listinfo/python-list
>

[toc] | [prev] | [next] | [standalone]


#61863

FromGrant Edwards <invalid@invalid.invalid>
Date2013-12-13 20:33 +0000
Message-ID<l8fqv2$nsl$1@reader1.panix.com>
In reply to#61858
On 2013-12-13, Vincent Davis <vincent@vincentdavis.net> wrote:
> Grant, Chris
> Thanks !!!

> I guess in the end this is a bad idea, (for my purposes) I should just use
> my gmail account smtp server.

If you're going to claim the mail is from <somebody>@gmail.com, then
yes you should definitly send it via Gmail's SMTP server.  Doing
anything else is going to be a long, losing battle involving you
learning more about SMTP and e-mail headers than you probably want to.

If you've got your own domain (which you're using as the "from"
address), a static IP, and your own MX record and corresponding SMTP
server, you should be able to set things up to send mail directly.

Many years ago (like 20), I used to configure my home Linux boxes to
send mail directly to the destination SMTP server while claiming to be
from "grante@<my-isp's-name>.com".  At first it worked fine that way.
Then about about 12-15 years ago, I started having problems with some
servers refusing my mail.  I had a static IP address with a real,
official hostname, so I set up an MX record for that hostname, and
made sure my handshaking configuration was using a hostname that
mapped back to my static IP address.  That helped for a while, but
SMTP servers continued to get more and more paranoid.  Some SMTP
servers won't accept mail from an IP if they've determined is a
"residential" IP address even if you do have a domain that matches the
"from" address, an MX record, and everything else.

Eventually, I just gave up and started routing everything through the
"official" SMTP server associated with the e-mail address from which I
wanted to send the mail.

-- 
Grant Edwards               grant.b.edwards        Yow! I'm having a MID-WEEK
                                  at               CRISIS!
                              gmail.com            

[toc] | [prev] | [next] | [standalone]


#61860

FromChris Angelico <rosuav@gmail.com>
Date2013-12-14 05:29 +1100
Message-ID<mailman.4092.1386959407.18130.python-list@python.org>
In reply to#61834
On Sat, Dec 14, 2013 at 5:27 AM, Vincent Davis <vincent@vincentdavis.net> wrote:
> Grant, Chris
> Thanks !!!
> I guess in the end this is a bad idea, (for my purposes) I should just use
> my gmail account smtp server.

If you're sending from gmail, use whatever gmail specifies for
sending. Otherwise your mail will be seen as spoofed.

The converse of this is that, in my opinion, *every* domain should
have an SPF record and *every* mail server should check them. That
would eliminate a huge slab of forged mail, and it'd prevent some
stupid web email forms from doing the wrong thing and only finding out
that it's wrong years later.

ChrisA

[toc] | [prev] | [next] | [standalone]


#61874

FromDennis Lee Bieber <wlfraed@ix.netcom.com>
Date2013-12-13 19:46 -0500
Message-ID<mailman.4103.1386982019.18130.python-list@python.org>
In reply to#61834
On Fri, 13 Dec 2013 11:27:00 -0700, Vincent Davis
<vincent@vincentdavis.net> declaimed the following:

>Grant, Chris
>Thanks !!!
>I guess in the end this is a bad idea, (for my purposes) I should just use
>my gmail account smtp server.
>

	Better, if you don't want to work with the potential hazzard of an ISP
that blocks passthrough SMTP; gmail is probably not using the regular SMTP
port. Original SMTP would accept mail from any sender, for any receiver...
Now known as an "open relay", and a source of much spam. Closed SMTP
requires that mail either come from an "inside" IP address (the DHCP
address issued to your connection by your ISP would be "inside" to the ISP
SMTP) or be addressed TO an address known by the SMTP (which is how your
ISP can send to some other network server -- it only sends to addresses on
that server, and multi-address messages will be sent to each domain as a
separate message).


	Back in my Amiga days, the first MTA I had /did/ attempt to connect
directly to the destination domain (but I suspect did not use MX record
lookup). Problem -- if it couldn't connect, that message would hang for
retry later... AND that hanging message blocked all subsequent queued
messages.

	My second client used ISP relay, leaving the headache of actually
delivering the message to my ISP to resolve. Problem: it extracted
destination addresses from the "To:" header of the message, and ignored
both "CC:" and "BCC:" headers (and, for all I know, even transmitted the
"BCC:" list to any "To" recipient).

	About then, I discovered the first two significant books on Python at
Computer Literacy, and that an Amiga binary was available (Python 1.4, I
think -- thanks, Irmin). In less than a week I'd hashed together an SMTP
sending program run as a daemon relaying through my ISP and properly
extracting SENDTO from To/CC/BCC headers [and removing the BCC from the
message], and an ARexx script used as the queuing module for AmigaELM. I
used this set-up for a few years until a fancier Amiga email program
arrived that handled sending and receiving internally (AmigaELM also
required an external POP3 fetchmail program -- the mail client only
accessed local mailbox files).
-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
    wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

[toc] | [prev] | [next] | [standalone]


#61902

FromIrmen de Jong <irmen.NOSPAM@xs4all.nl>
Date2013-12-14 16:48 +0100
Message-ID<52ac7db0$0$2975$e4fe514c@news.xs4all.nl>
In reply to#61874
On 14-12-2013 1:46, Dennis Lee Bieber wrote:

> 	About then, I discovered the first two significant books on Python at
> Computer Literacy, and that an Amiga binary was available (Python 1.4, I
> think -- thanks, Irmin).

You're welcome, but my name is spelled Irmen, with an 'e' ;-)

Cheers
Irmen

[toc] | [prev] | [next] | [standalone]


#61907

FromDennis Lee Bieber <wlfraed@ix.netcom.com>
Date2013-12-14 12:59 -0500
Message-ID<mailman.4118.1387043968.18130.python-list@python.org>
In reply to#61902
On Sat, 14 Dec 2013 16:48:00 +0100, Irmen de Jong <irmen.NOSPAM@xs4all.nl>
declaimed the following:

>On 14-12-2013 1:46, Dennis Lee Bieber wrote:
>
>> 	About then, I discovered the first two significant books on Python at
>> Computer Literacy, and that an Amiga binary was available (Python 1.4, I
>> think -- thanks, Irmin).
>
>You're welcome, but my name is spelled Irmen, with an 'e' ;-)
>
	I knew I should've flagged it with a (?sp) 

	Sorry.
-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
    wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web