Reputation: 131
I have errors when I use reply_to, here is what I've tried...
This works but without reply_to :
mail = Mail(
from_email = from_email,
to_emails = to_email,
subject = subject,
html_content = content)
response = sg.client.mail.send.post(request_body=mail.get())
And I've tried this :
mail = Mail(
reply_to = reply,
from_email = from_email,
to_emails = to_email,
subject = subject,
html_content = content)
response = sg.client.mail.send.post(request_body=mail.get())
This thows :
TypeError: init() got an unexpected keyword argument 'reply_to'
I have also tried to add this after Mail() :
mail.from_EmailMessage(reply_to=ReplyTo(Email(email=ANS_EMAIL,name='Mr X')))
Which throws :
TypeError: object of type 'Email' has no len()
And :
mail.reply_to(ReplyTo(email=ANS_EMAIL,name='Mr X'))
Which throws :
TypeError: 'NoneType' object is not callable
Any help please ?
Upvotes: 4
Views: 2346
Reputation: 131
I managed doing this :
data = {
"personalizations": [
{
"send_at": date,
"subject": objet,
"to": [{"email": to_email}],
}
],
"from": {"email": FROM_EMAIL, "name": "..."},
"reply_to": {"email": "...@...", "name": "..."},
"send_at": date,
"subject": objet,
"content": [
{
"type": "text/html",
"value": body
}
]
}
response = sg.client.mail.send.post(request_body=data)
Upvotes: 2
Reputation: 2710
As your error states reply_to
is not accepted in init()
. Try setting reply_to
after you have created the Mail object.
Example Below:
mail.reply_to = "[email protected]"
or
message.reply_to = ReplyTo('[email protected]', 'Reply Here')
More details on how to customize sendgrid email object - Link
Upvotes: 6