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

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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.