I have some Python script that sends emails with an attachment. This attachment is passed as a bytes
object and is always displayed on Outlook and Gmail web apps on my computer, and on Gmail and Outlook apps on iPhone and Android. However, it is never displayed on iPhone native Email app, which is called "Mail".
Here is my script, self._attachment
is the PNG as bytes.
# Create a multipart message and set headers
# Create a multipart message and set headers
message = MIMEMultipart('related')
message["From"] = self.prepare_from_field(self._sender_name, self._sender_account)
message["Subject"] = self.prepare_email_subject(self._subject_type)
message["To"] = self.prepare_recipients(self._list_of_recipients)
message["Cc"] = self.prepare_recipients(self._list_of_cc)
message["Bcc"] = self.prepare_recipients(self._list_of_bcc)
# Encapsulate the plain and HTML versions of the message body in an
# 'alternative' part, so message agents can decide which one they want to display.
msgAlternative = MIMEMultipart('alternative')
body = self.prepare_body(self._list_of_texts, self._list_of_disclaimers, self._extra_code, None)
msgText = MIMEText(body, 'html')
msgAlternative.attach(msgText)
message.attach(msgAlternative)
# message.attach(MIMEText(body, "html"))
# Add attachment if required
if self._attachment is not None:
message.attach(MIMEImage(self._attachment, name='Your png.png'))
# Prepare the entire email as string
text = message.as_string()
all_recipients = self.absolute_list_of_recipients(self._list_of_recipients, self._list_of_cc, self._list_of_bcc)
with smtplib.SMTP(at.smtp_config['smtp_server'], at.smtp_config['smtp_non_sll_port']) as server:
context = ssl.create_default_context()
server.starttls(context=context)
server.ehlo()
# Log in with credentials
server.login(at.user_credentials['username'], at.user_credentials['password'])
# Send the emailu
server.sendmail(senders_account, recipient_address, message)
return True
Would you know why iPhone's Mail app does not display the png file attached and how to solve it without compromising the display on other apps and devices?
Thank you in advance!