Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Track some emails with gmail gem

I'm using gmail gem to send emails and I need track these emails. How can I do this?

I'm trying search the email with the message_id, but it bring all emails from my inbox and I want just the responses of a specific email.

Here is my actual code:

*save email with the message_id*

mail = gmail.deliver(email)
Email.create(:message_id => mail.message_id, :from => user.email,
  :to => annotation.to, :body => annotation.content, :title => annotation.title,
  :annotation => annotation, :user => user)

*search the mails with message_id*

messages = gmail.inbox.mails(:message_id => email.message_id)

Regards,

Fabrício Ferrari de Campos

like image 584
Fabrício Avatar asked May 19 '11 20:05

Fabrício


2 Answers

you can take Net::IMAP a look.

uid =  gmail.conn.uid_search(["HEADER", "Message-ID", "<[email protected]>"])[0]
#=> 103
message = Gmail::Message.new(gmail.inbox, uid)
#=>  #<Gmail::Message0x12a72e798 mailbox=INBOX uid=103> 
message.subject
#=> "hello world"
message.message_id
#=> "<[email protected]>"

have not find a method can search by message_id.via this way you can get a specific email.

like image 155
Ankun Avatar answered Nov 06 '22 11:11

Ankun


Using the standard gmail gem, this seems to work quite well

messages = gmail.inbox.mails(:query => ['HEADER', 'Message-ID', email.message_id])
like image 34
Cyberfox Avatar answered Nov 06 '22 13:11

Cyberfox