pythonメールウィジェット1枚
#!/usr/bin/env python
# Import smtplib for the actual sending function
import sys
import getopt
import smtplib
sender = '[email protected]' #
# If there are more than one receiver, you need to ganerate a list.
receiver = ['[email protected]','[email protected]'] #
cc_receiver = ['[email protected]'] #
server = 'smtp.163.com' #
port = '25' #
pwd = 'xxxx' #
COMMASPACE = ', '
# Import the email modules we'll need
#from email.mime.text import MIMEText
from email.MIMEText import MIMEText
from email.Header import Header
def usage():
usageStr = '''Usage: SendEmail -s "subject" -c "mail_content"'''
print usageStr
def main(argv):
# Get the Email content in the "-c" argv
try:
opts, args = getopt.getopt(argv, "s:c:")
except getopt.GetoptError:
usage()
sys.exit(2)
subject = ''
content = ''
for opt, arg in opts:
if opt == '-c':
content = arg
if opt == '-s':
subject = arg
print content
msg = MIMEText(content)
msg['Subject'] = subject
msg['From'] = sender
msg['To'] = COMMASPACE.join(receiver)
msg['Cc'] = COMMASPACE.join(cc_receiver)
s = smtplib.SMTP(server, port)
s.ehlo()
s.login(sender, pwd)
s.sendmail(sender, receiver, msg.as_string())
s.sendmail(sender, cc_receiver, msg.as_string())
s.quit()
if __name__=="__main__":
main(sys.argv[1:])
メールの送信方法:
python sendmail.py-s「タイトル」-c「送信内容」