简体   繁体   中英

How to send an e-mail from a Python script that is being run on “Google App Engine”?

How could I send an e-mail from my Python script that is being run on " Google App Engines " to one of my mail boxes?

I am just a beginner and I have never tried sending a message from a Python script. I have found this script (IN THIS TUTORIAL) : 替代文字

Here is the same script as a quote:


import sys, smtplib

fromaddr = raw_input("From: ")
toaddr = string.splitfields(raw_input("To: "), ',')
print "Enter message, end with ^D:"
msg = ''
while 1:
    line = sys.stdin.readline()
    if not line:
        break
    msg = msg + line

# The actual mail send
server = smtplib.SMTP('localhost')
server.sendmail(fromaddr, toaddrs, msg)
server.quit()

but I hardly understand how I could have this script run from "Google App Engine":

1) Firstly, I don't quite understand what e-mail address I need to place right after From: in this line:


fromaddr = raw_input("From: ")

Can I just place here any e-mail address of any e-mail boxes that I have?

2) Secondly, let's say I want to send a message to this e-mail address of mine brilliant@yahoo.com . Then the next line, I guess, must look this way:


toaddr = string.splitfields(raw_input("To: brilliant@yahoo.com"), ',')

Is this right?

3) Thirdly, let's say, the message that I want to send will be this sentence: Cats cannot fly! Then, I guess, the line that starts with msg = must look this way:


msg = 'Cats cannot fly!'

Is this correct?

4) If I upload this script as an application to "GAE", how often will it be sending this message to my mail box? Will it send this message to me only once or it will be sending it to me every second all the time until I delete the application? (This is why I haven't tried uploading this script so far)

Thank You all in advance for Your time and patience.

Sure - just use the Mail API as outlined in the docs:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM