thoughtbot/griddler

Getting the envelope with griddler and griddler-sendgrid

Closed this issue · 6 comments

I am having a hard time accessing the envelope of the email.

`class EmailProcessor
include Parser

def initialize(email)
@email = email

end

def process

  to=@email.from[:email]

  bank=@email.to.first[:token]

puts "******  #{@email.envelope}"

end

end
`
I get: Undefined method 'envelope' for #Griddler::Email:...>.
What would be the best way to access the envelope? thanks

Griddler does not parse the envelope independently. It appears the SendGrid adapter uses the envelope to parse some information but does not expose it "downstream". Is the information you need not available in the headers or raw headers? If there's information you need that isn't available you may have to file an issue over in the SendGrid adapter.

Sorry for no links. Commenting on the run via my phone.

In the context of receiving emails which could have been put on as :bcc, I am trying to get the envelope to extract the "to" field which would allow me to identify to which bcc this particular email was sent and process it accordingly.
I see that this "bcc" email name is also appearing in the raw_headers or "inspect" of the @email object, but I would need to parse that manually to extract it, unless there is a way which I am not aware of.

I assume quite a few people would want to achieve the same, i.e. being able to easily identify which bcc they are dealing with. thanks

The concept of a standalone envelope is not exposed by all providers that Griddler supports. Given that various providers will expose extract different aspects of the incoming email, it is up to each adapter to parse/populate those aspects. That being said, so long as the provider does not strip the headers that make up the envelope, they should be available via the headers or raw_headers attributes provided by Griddler.

bcc is already exposed as an instance variable on Griddler::Email'](https://github.com/thoughtbot/griddler/blob/master/lib/griddler/email.rb#L6). The SendGrid adapter [will already extract bccfrom theto` portion of the envelope as defined by SendGrid. So, I'm still not clear on what information you require that is not already exposed.

AS an example, I am sending an email to : abc1@toast.com from abc2@toast.com and I put : require@parse.toast.com in bcc. Once this email is captured by the Parse sendgrid, I can see require@parse.toast.com in the raw_headers, but @mail.bcc returns an empty array. Am I missing something? thanks

No, that should be the right way of accessing it. Looks like thoughtbot/griddler-sendgrid#17 may be of interest. You need to be running the master branch of the gem to have working bcc.

After getting the griddler-sendgrid adapapter gem from their "master" branch I am able to access the bcc as expected. So that would be the solution to my issue. cheers