Code up email message in Python - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Code up email message in Python

BonkersBonkers Posts: 1Member
[b][red]This message was edited by Bonkers at 2002-10-2 1:24:59[/red][/b][hr]

Hi,
Have a task from my teacher: "Send me an email made by Python"
Ok, cool!
Plz direct me somewhere to find this code module!!!!!!!!
Cheers, Bonkers :-)

Comments

  • rafcrafc Posts: 4Member
    : [b][red]This message was edited by Bonkers at 2002-10-2 1:24:59[/red][/b][hr]
    :
    : Hi,
    : Have a task from my teacher: "Send me an email made by Python"
    : Ok, cool!
    : Plz direct me somewhere to find this code module!!!!!!!!
    : Cheers, Bonkers :-)

    You can read "email" module and find informations about sending email.
    This code use "smtplib" and is taken from Python tutorial. Try this:

    import smtplib
    import string

    def prompt(prompt):
    return raw_input(prompt).strip()

    fromaddr = prompt("From: ")
    toaddrs = prompt("To: ").split()
    print "Enter message, end with ^D:"

    # Add the From: and To: headers at the start!
    msg = ("From: %s
    To: %s

    "
    % (fromaddr, string.join(toaddrs, ", ")))
    while 1:
    try:
    line = raw_input()
    except EOFError:
    break
    if not line:
    break
    msg = msg + line

    print "Message length is " + `len(msg)`

    server = smtplib.SMTP('localhost')
    server.set_debuglevel(1)
    server.sendmail(fromaddr, toaddrs, msg)
    server.quit()


Sign In or Register to comment.