View Problem
Send an email
Use library functions, classes or objects to create a short email addressed to your own email address. The subject should be,
Submit a new solution for python
There are 10 other solutions in additional languages (fantom, fsharp, groovy, java ...)
"Greetings from langref.org", and the user should be prompted for the message body, and whether to cancel or proceed with sending the email.
python 2.5
import smtplib
import locale
from email.mime.text import MIMEText
encoding = locale.getpreferredencoding()
def main():
smtp_servername = "smtp.example.com"
from_addr = "ernie@example.com"
to_addr = "cookie.monster@mailinator.com"
body = raw_input("Enter the email message ")
if not raw_input("Send email? y/N ") in ["y", "Y"]:
print "aborting"
return
message = MIMEText(body, _charset=encoding)
message["From"] = from_addr
message["To"] = to_addr
message["Subject"] = "Greetings from langref.org"
server = smtplib.SMTP(smtp_servername)
server.sendmail(from_addr, to_addr, message.as_string())
if __name__ == "__main__":
main()
import locale
from email.mime.text import MIMEText
encoding = locale.getpreferredencoding()
def main():
smtp_servername = "smtp.example.com"
from_addr = "ernie@example.com"
to_addr = "cookie.monster@mailinator.com"
body = raw_input("Enter the email message ")
if not raw_input("Send email? y/N ") in ["y", "Y"]:
print "aborting"
return
message = MIMEText(body, _charset=encoding)
message["From"] = from_addr
message["To"] = to_addr
message["Subject"] = "Greetings from langref.org"
server = smtplib.SMTP(smtp_servername)
server.sendmail(from_addr, to_addr, message.as_string())
if __name__ == "__main__":
main()
Submit a new solution for python
There are 10 other solutions in additional languages (fantom, fsharp, groovy, java ...)


