Specify a sender when sending mail with Python (smtplib)

前端 未结 6 1245
不思量自难忘°
不思量自难忘° 2020-12-02 00:19

I have a very simple piece of code (just for testing):

import smtplib
import time

server = \'smtp.myprovider.com\'
recipients = [\'johndoe@somedomain.com\']         


        
6条回答
  •  星月不相逢
    2020-12-02 00:29

    smtplib doesn't automatically include a From: header, so you have to put one in yourself:

    message = 'From: me@example.com\nSubject: [PGS]: Results\n\nBlaBlaBla'
    

    (In fact, smtplib doesn't include any headers automatically, but just sends the text that you give it as a raw message)

提交回复
热议问题