I'm using Gmail API in Python and trying to send an email with Latex in it. I'm aware of extensions and
add-ons that make already make it possible to send gmail messages using Latex.
My error isn't in the python code, rather it's in the email. The email contains no body and an attachment
that says "noname" all other fields are filled correctly. I haven't found anything online that's similar to my issue.
From my understanding I might be using the incorrect mime type or Gmail isn't understanding what I've put
into body of email.
1. I've verified email did get sent with plain text before using any latex.
2. verfied receiver did get message
3. verified message sent and received using the latex, but has "noname" attachment.
4. tried text/html, application/x-latex, text/plain but html and latex doesn't work.
5. json and credential file are up to date with everthing
6. I've tried sympy but not really useful either:
'''
func = sp.Function('func')
x = sp.Symbol('x')
func = sp.sin(x)
message_text = func
'''
here is snippents to my code:
Create a message for an email.
Args:
sender: Email address of the sender.
to: Email address of the receiver.
subject: The subject of the email message.
message_text: The text of the email message.
Returns:
An object containing a base64url encoded email object.
'''
def create_message(sender, to, subject, message_text):
message_text = "$x^2"
#message = MIMEText(message_text)
message = MIMEText(message_text, 'application/x-latex')
message['to'] = to
message['from'] = sender
message['subject'] = subject
return {'raw': base64.urlsafe_b64encode(message.as_string().encode()).decode()}#changed as_string() to as_string().encode()).decode
'''
Send an email message.
Args: service: Authorized Gmail API service instance. user_id: User's email address. The special value "me" can be used to indicate the authenticated user. message: Message to be sent.
Returns: Sent Message.
'''
def send_message(service, user_id, message):
try:
message = (service.users().messages().send(userId=user_id, body=message)
.execute())
print ('Message Id: %s' % message['id'])
return message
except errors.HttpError as error:
print ('An error occurred: %s' % error)
'''