message.eml path for mail gem ruby on rails

北战南征 提交于 2019-12-12 00:22:32

问题


I am trying to read my gmail inbox using the mail gem. I am able to get the message array using Mail.last.

Now I want to READ this message. The documentation says--

ail = Mail.read('/path/to/message.eml')

mail.envelope.from   #=> 'mikel@test.lindsaar.net'
mail.from.addresses  #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
mail.sender.address  #=> 'mikel@test.lindsaar.net'
mail.to              #=> 'bob@test.lindsaar.net' 
mail.cc              #=> 'sam@test.lindsaar.net'
mail.subject         #=> "This is the subject"
mail.date.to_s       #=> '21 Nov 1997 09:55:06 -0600'
mail.message_id      #=> '<4D6AA7EB.6490534@xxx.xxx>'
mail.body.decoded    #=> 'This is the body of the email...

Now, the problem remailns - what is /path/to/message/eml ? How do i create/locate this EML file?

Thanks.


回答1:


I've not used this gem, but looking at the README, should be that Mail.last returns an instance of Mail.

You say Mail.lasts works, i.e. it retrieves the email from gmail given your settings https://github.com/mikel/mail#getting-emails-from-a-pop-server

What happens when you do:

mail = Mail.last
mail.body.decoded



回答2:


I know it's a bit late to answer, to say the least.. But hey if anyone will be able to use it:

Once you iterate over the mails, you can just use something like this.

mails = Mail.all

mails.each do |current_mail|
    mail_object = Mail.read_from_string(current_mail)
    puts mail_object.to # Outputs the To address 
end

I also suggest checking the full documentation here: http://www.rubydoc.info/github/mikel/mail/Mail

Cheers :)



来源:https://stackoverflow.com/questions/20070204/message-eml-path-for-mail-gem-ruby-on-rails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!