4

我正在寻找一种使用 Gmail SMTP 发送谷歌模式的方法。发件人和收件人是一样的。

该架构使用http://gmail-actions.appspot.com/工作正常, 但如果我在 python 脚本中复制相同的内容(如下所示),它就不起作用。

import smtplib

# The below code never changes, though obviously those variables need values.
session = smtplib.SMTP('smtp.gmail.com', 587)
session.ehlo()
session.starttls()
GMAIL_USERNAME = "MY_EMAIL@gmail.com"
GMAIL_PASSWORD = "MY_PASSWORD"
email_subject = "This is the subject"
body_of_email = '<html> <head><script type="application/ld+json">{ "@context": "http://schema.org", "@type": "FlightReservation", "reservationNumber": "RXJ34P", "reservationStatus": "http://schema.org/Confirmed", "underName": {"@type": "Person","name": "Eva Green" }, "reservationFor": {"@type": "Flight","flightNumber": "110","airline": { "@type": "Airline", "name": "United", "iataCode": "UA"},"departureAirport": { "@type": "Airport", "name": "San Francisco Airport", "iataCode": "SFO"},"departureTime": "2017-03-04T20:15:00-08:00","arrivalAirport": { "@type": "Airport", "name": "John F. Kennedy International Airport", "iataCode": "JFK"},"arrivalTime": "2017-03-05T06:30:00-05:00" }}</script> </head> <body><p> This a test for a Rate action in Gmail. </p> </body></html>'
recipient = "MY_EMAIL@gmail.com"
session.login(GMAIL_USERNAME, GMAIL_PASSWORD)
headers = "\r\n".join(["from: " + GMAIL_USERNAME, "subject: " + email_subject, "to: " + recipient, "mime-version: 1.0", "content-type: text/html"])

content = headers + "\r\n\r\n" + body_of_email
session.sendmail(GMAIL_USERNAME, recipient, content)

电子邮件标头似乎没有 SPF 或 DKIM 签名。

我应该怎么办 ?谢谢

4

0 回答 0