+ Start a Discussion
Sohel Shaikh 23Sohel Shaikh 23 

How to read email and its attachement using apex?

Requirement:
I want to check if my mailbox has received an email from specific sender and read the excel sheet attached to it and use the data in excel sheet in my apex code.
N.M. SharmaN.M. Sharma
Hi Sohel,

You can make a trigger on EmailMessage and then check if whatever specific sender you want in it.
Please check this link:

https://developer.salesforce.com/blogs/developer-relations/2009/10/one-of-the-things-about-working-for-a-company-that-innovates-at-such-an-incredible-pace-is-that-you-are-constantly-tasked-wit.html

And for checking Attachment make a query on attachment where ParentId = EmailMessage.id.

Using this you easily grab your file.

Thanks