コード例 #1
0
ファイル: mailman.py プロジェクト: cychenyin/windmill
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)
コード例 #2
0
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)
コード例 #3
0
ファイル: use_mailer.py プロジェクト: rkemmetmueller/mailer
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"
コード例 #4
0
ファイル: use_mailer.py プロジェクト: arunsingh/mailer
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"