Thanks for your kind help, i managed to follow mailgunn's latest documentation to create the function below. https://documentation.mailgun.com/en/latest/api-sending.html#examples
However, when running the script/ sending the email, i still get the error that says " UnicodeDecodeError: 'cp932' codec can't decode byte 0xe0 in position 3: illegal multibyte sequence". i googled abit and found that the problem is in the error encoding. Basically, i am drawing a plot using matplotlib/seaborn and doing a plt.savefig("TEST.jpg").
can u help me with this error?
# function to send email out
def Heroku_Mailgun_Send_Email(self, Email_to, Email_subject, Email_body, FileAttachment, ChartImage, Email_API_key, Email_domain):
return requests.post(
f"https://api.mailgun.net/v3/{Email_domain}/messages",
auth=("api", Email_API_key),
files=[("inline", open(ChartImage)),
("attachment", (FileAttachment, open(FileAttachment,"rb").read()))],
data={"from": f"NG Ying Jian <mailgun@{Email_domain}>",
"to": Email_to,
"subject": Email_subject,
"text": Email_body,
"html": f'<html>Chart image here: <img src="cid:{ChartImage}"></html>'})
###################################
Im using python, and trying to build a function that sends out an email with a 'png' format image file in it (passed over by the argument called "ChartImage"). However, when i use this function below to send out below, the image doesnt get sent out. it says "The linked image cannot be displayed. the file may have been moved, renamed or deleted..."
my gut feeling tells me i need to insert something "inline" in the "files=" portion so that it can be called below in the , but i dont know how to do it. able to help?
# function to send email out
def Heroku_Mailgun_Send_Email(Email_to, Email_subject, Email_body, FileAttachment, ChartImage, Email_API_key, Email_domain):
return requests.post(
f"https://api.mailgun.net/v3/{Email_domain}/messages",
auth=("api", Email_API_key),
files=[("attachment", (FileAttachment, open(FileAttachment,'rb').read()))],
data={
"from": f"NG Ying Jian <mailgun@{Email_domain}>",
"to": Email_to,
# "cc": "baz@example.com",
# "bcc": "bar@example.com",
"subject": Email_subject,
"text": Email_body,
"html": f"<html> \
<head> \
<title>HTML img Tag</title> \
</head> \
<body> \
<img src={ChartImage} width='1000' height='500'>> \
</body> \
</html>",
})