How to Get Gmail Oauth or Xauth Tokens with Omniauth

fetch gmail with oauth2

Nope, just OAuth 1.0 right now.

Gmail SMTP + XOAuth mystery

The problem is on how you do the SMTP connection here is a snippet from my code:

    smtp_conn = smtplib.SMTP('smtp.googlemail.com', 587)
#smtp_conn.set_debuglevel(True)
smtp_conn.ehlo()
smtp_conn.starttls()
smtp_conn.ehlo()
smtp_conn.docmd('AUTH', 'XOAUTH ' + base64.b64encode(xoauth_string))

You create the xoauth_string as in the example from Google. After that you can use smtp_conn to send your email. If you have any problems let me know. You can find some sample code at https://github.com/PanosJee/xoauth

How to read the body text of an email using ruby's net/imap library?

If you just want just the body content of the message you can use:

body = imap.fetch(message_id,'BODY[TEXT]')[0].attr['BODY[TEXT]']

The IMAP API is a bit esoteric though. If you want to deal with the whole message, I would recommend using TMail to parse it into an easier to use format:

msg = imap.fetch(message_id,'RFC822')[0].attr['RFC822']
mail = TMail::Mail.parse(msg)
body = mail.body


Related Topics



Leave a reply



Submit