I'm making a program that replies automatically to emails on my GMail account. I can send mails just fine, but I can't seem to reply to them. I'm using smtplib
.
This is the code I use for sending plain mails (suppose that foobar@gmail.com
is my personal email):
# params contains the header data of the original email.
print smtpserver.sendmail(
"Name Surname <foobar@gmail.com>",
str(params["From"]),
msg
)
This is what I use to send replies:
print smtpserver.sendmail(
"Giul Mus <giul.mus@gmail.com>",
str(params["From"]),
msg,
{
"In-Reply-To": params["Message-ID"],
"Message-ID": email.utils.make_msgid(),
"References": params["Message-ID"],
"Subject": "Re: " + params["Subject"]
}
)
The former works correctly, and I can see the mail it sent in my mailbox; however, the latter fails with this stack trace:
Traceback (most recent call last):
File "imap.py", line 65, in <module>
imapprocess(imapdata[0].split(" "))
File "imap.py", line 55, in imapprocess
raise e
smtplib.SMTPSenderRefused: (555, '5.5.2 Syntax error. o2sm22774327wjo.3 - gsmtp', 'Name Surname <foobar@gmail.com>')
Why does this happen? I saw this, question, but it wasn't of any help (I tried sending it from "Foo Bar <foobar@gmail.com>"
, "<foobar@gmail.com>"
, or to "<hardcoded-address@gmail.com>"
, but none of these worked).