문제

I need to have 'cid' in this script as the subject line in an email. It can't just be in the message body or header, but the actual subject line in the recipient's inbox

import smtplib

cid = raw_input()
cmd = #output from a script

to = 'my@email.com'
m_login = 'recipient@email.com'
m_pwd = 'mypassword'
header = 'To:' + to + '\n' + 'From:' + m_login + '\n' + '\n'

smtpserver = smtplib.SMTP("smtp.outgoingserver.com",587)
smtpserver.ehlo()
smtpserver.ehlo
smtpserver.login(m_login, m_pwd)
mail = header + cmd     
smtpserver.sendmail(m_login, to, mail)
smtpserver.close()
도움이 되었습니까?

해결책

The Subject: header is what's displayed in the recipient's inbox. So your stipulation that this not be in the headers makes no sense at all. Just add it to your headers, e.g.:

header = 'To: %s\nFrom: %s\nSubject: %s\n\n' % (to, m_login, cid)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top