带有空主体和主题的Python Mail

时间:2019-01-29 07:40:31

标签: python-2.7 email smtp

我正在尝试使用以下代码在python 2.7中发送邮件。但是我收到的主题和内容空着的邮件。它使用导入smtplib。当我尝试打印主题和文本时,它会成功打印。但是消息来了。

#!/usr/bin/python
def mailing(name, stat):
    if stat == 'SHUTDOWN':
        Subj = 'Major: '
    else:
        Subj = 'Critical:'
    print '************ SENDING MAIL ************'
    print 'Name:  ' + name
    print 'Status:  ' + stat
    print 'Domain: ' + domain
    SERVER = '***********'
    FROM = '***********'
    TO = ['***********']  # must be a list
    SUBJECT = Subj + 'The Weblogic server instance ' + name + ' is ' \
        + stat
    print SUBJECT
    TEXT = 'The Server ' + name + ' in ' + domain + ' Environment is ' \
        + stat

    # Prepare actual message
    message = """\
    From: %s
    To: %s
    Subject: %s

    %s
    """ % (FROM, ", ".join(TO), SUBJECT, TEXT)    

    # Send the mail
    server = smtplib.SMTP(SERVER)
    server.sendmail(FROM, TO, message)
    print '************ MAIL SEND ************'
    server.quit()

0 个答案:

没有答案