0
votes

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)

'''



email in gmail with an attachement "noname"

1
To what I have understood of your question: you want to send an email with a Latex attachment and no body. Am I right? If so, for the attachment you will need to follow the send an attachment in an email message guide of the Gmail API. Let me know if I got right what you are trying to do here and if it was of any help the guide.Mateo Randwolf
Sorry about the confusion, I meant for latex within the body and no attachment.Raul Zarate
Is latex a file that required to be attached or is it just a string of text? According to this the body message must be of type string and the rest must be attached as media in the email's body.Mateo Randwolf

1 Answers

0
votes

Explanation

According to the documentation your MIME type of application/x-latex is interpreted by the API as an attachment MIME type.

In the link above, you can see what google recognises as this. Bare in mind that it mentions that for the ones not recognised App Engine will assign the MIME type application/octet-stream.

This is the reason why when you send the message without specifying the MIME type the user will receive an email with $x^2 in the body while when you specify to be using Latex the user gets an attachment with no name specified but with $x^2 in its content.