def sendmail(mailto, subject, html='', text='', textfile='', htmlfile='', attachments=''): '''send mail''' if not mailto: print 'Error: Empty mailto address.\n' return mailto = [sb.strip() for sb in mailto.split(',')] if attachments: attachments = [att.strip() for att in attachments.split(',')] else: attachments = [] #USERNAME = hostname() subject = "%s-[%s]" % ( subject, hostname()) message = Message(From=USERNAME, To=mailto, Subject=subject, attachments=attachments) message.Body = text message.Html = html message.charset = 'utf8' try: if htmlfile: message.Html += open(htmlfile, 'r').read() if textfile: message.Body += open(textfile, 'r').read() except IOError: pass for att in attachments: message.attach(att) sender = Mailer(SERVER,port=465, use_tls=True, usr=USERNAME, pwd=PASSWD) #sender = Mailer(SERVER) #sender.login(USERNAME, PASSWD) sender.send(message)
def sendmail(mailto, subject, html='', text='', textfile='', htmlfile='', attachments=''): '''send mail''' if not mailto: print 'Error: Empty mailto address.\n' return mailto = [sb.strip() for sb in mailto.split(',')] if attachments: attachments = [att.strip() for att in attachments.split(',')] else: attachments = [] #USERNAME = hostname() subject = "%s-[%s]" % (subject, hostname()) message = Message(From=USERNAME, To=mailto, Subject=subject, attachments=attachments) message.Body = text message.Html = html message.charset = 'utf8' try: if htmlfile: message.Html += open(htmlfile, 'r').read() if textfile: message.Body += open(textfile, 'r').read() except IOError: pass for att in attachments: message.attach(att) sender = Mailer(SERVER, port=465, use_tls=True, usr=USERNAME, pwd=PASSWD) #sender = Mailer(SERVER) #sender.login(USERNAME, PASSWD) sender.send(message)
from mailer import Message import urllib msg1 = Message(From="*****@*****.**", To=["*****@*****.**", "*****@*****.**"], charset="utf-8") msg1.Subject = "日本語のHTMLメール" msg1.Html = """Hello, <b>日本語</b>""" mailer = Mailer('smtp01.odn.ne.jp') msg2 = Message(Body="ナイスボディー!", attachments=["picture.png"]) msg2.From = "*****@*****.**" msg2.To = "*****@*****.**" msg2.Subject = "日本語の添付ファイルメール" msg2.charset = "utf-8" mailer.send([msg1, msg2]) msg = Message() msg.From = "*****@*****.**" msg.To = "*****@*****.**" msg.Subject = "テキストメール" msg.Body = "これは日本語のキストメールでございます。" msg.charset = "utf-8" mailer.send(msg) msg3 = Message(From="*****@*****.**", To=["*****@*****.**", "*****@*****.**"], charset="utf-8") msg3.Subject = "HTML with Attachment"