I need to get the name and email address from a forwarded email where there is a line like this in the body:
From: john smith <sales@domain.com>
What is the best way to do this? Is there a good library/gem I should use?
Also this line will vary from which email client it’s sent from and also what language, so I need a more robust way than just matching just this string.
Also some clients do not include the name but just the email address on this line so I need to be able to handle that.
The
Mailobject is automatically included in Rails projects that useActionMailer– but you’ll need to add it to yourGemfileif you’re not usingActionMailerUpdate
I didn’t read the OP’s question properly – they want to get an email address from the body of a forwarded mail. I’d just use some regex:
NB: this assumes a fair amount about the structure of the email – an HTML-only email can easily thwart this regex.