subject with smtplib?

J

Jeff Sandys

Can you include a subject with sendmail using smtplib?

When I do this (names changed to protect the innocent):

import smtplib
toadr = "(e-mail address removed)"
frmadr = "(e-mail address removed)"
msg = "this is an important message."
server = smtplib.SMTP('localhost')
server.sendmail(frmadr, toadr, msg)
server.quit()

I get the important message with a blank subject line.
It would be really useful to add a subject line,

sub = "important message"
server.sendmail(frmadr, toadr, msg, subject=sub)

I've looked through the documentation and see that
there is a mail_options but haven't found anything
about adding a subject.

Thanks,
Jeff Sandys
 
D

Dennis Lee Bieber

Can you include a subject with sendmail using smtplib?

When I do this (names changed to protect the innocent):

import smtplib
toadr = "(e-mail address removed)"
frmadr = "(e-mail address removed)"

These lines only define the handshaking done with the SMTPd.
They do not define the "to:" and "from:" headers of most email.
msg = "this is an important message."

msg should include the ENTIRE message, including the headers
that you expect the receiver to view...


Look at it this way:

"""
Date: a long time ago
From: (e-mail address removed)
To: (e-mail address removed)
Subject: This is junk mail

Free samples of drug of your choice
"""

is the "letter"... "From" is the sender address (corporate letterhead),
"To" is the /inside address/ (look at any book on formatting business
letters).

The "frmadr" and "toadr" are the addresses you put on the
outside of the envelope -- and don't even have to match what is on the
inside (this is how BCC: works -- the sending program puts the BCC:
addresses into "toadr" [the envelopes], and then removes the BCC: from
the letter itself so they don't show).

--
 

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,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top