Using pythons smtp server

V

Vincent Davis

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
 
G

Grant Edwards

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 <[email protected]>
Subject: Re: Using pythons smtp server
References: <[email protected]>
Followup-To:

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
 
C

Chris Angelico

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
 
V

Vincent Davis

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
 
C

Chris Angelico

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
 
G

Grant Edwards

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.
 
D

Dennis Lee Bieber

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).
 
I

Irmen de Jong

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top