Reputation: 151
I need a mail parser application, which parses periodically some incoming mails.
azure
provide such tool? SendGrid seems just to enable sending outgoing mails and receiving some events.Upvotes: 4
Views: 6626
Reputation: 5401
Logic Apps provide the POP3 connector that allows you to do this. The connector acts as trigger to kick-off your Logic App workflow. In order to achieve this - you need to:
A detailed description can be found here: https://github.com/Huachao/azure-content/blob/master/articles/app-service-logic/app-service-logic-connector-pop3.md
Upvotes: 2
Reputation: 751
More than 3 years later, but I think (and hope) this can help people facing this situation:
https://ml-software.ch/posts/receving-emails-using-sendgrid-inbound-parse
As @Jan Hajek said, you can make use of Sendgrid inbound parse. The post doesn't share the whole code but it gives some snippet and an idea of how to implement it on Azure function.
EDIT: This is the piece of code that referred post owner used to accept email, parse it and create a POST request to a defined endpoint:
try
{
// Use StrongGrid to parse the request body (handling multipart/form-data is not so simple)
var parser = new WebhookParser();
var inboundMail = parser.ParseInboundEmailWebhook(req.Body);
// Use an email parser to get only the visible text. The visible text will be the text that the user replied and not the whole text of the email with the original email.
var email = EmailParser.Parse(inboundMail.Text);
var data = new
{
To = inboundMail.To.FirstOrDefault()?.Email,
From = ExtractEmail(inboundMail.From.Email),
BookingNumber = GetBookingNumberFromEmail(inboundMail.To.FirstOrDefault()?.Email),
Text = email.GetVisibleText(),
Html = inboundMail.Html
};
log.LogInformation(JsonConvert.SerializeObject(data, Formatting.Indented));
messages.Add(new Message
{
Label = "NewEmailFromGuestEvent",
Body = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(data))
});
return new OkResult();
}
catch (Exception ex)
{
log.LogError(ex.Message);
return new BadRequestResult();
}
According to author:
It uses StrongGrid (NuGet Package) for parsing the incoming WebHook
First, parse the request body with StrongGrid. This will return a strongly typed object with all the data that was sent from SendGrid. Then, use another library to parse the text of the email. In this application, you only want the reply what the user sent, without the history. For this you can use EmailReplyParser (NuGet package). This project is not very active so you might have to change it later on, but for now it does what we need to. Then the final step for now is to create an anonymous object, pack all the data that is required into it and then create a new entry on the Azure Queue. Inside of the application, you can handle messages that are being added to the queue and extract the information required.
This might be a little beyond the actual parser that was asked, but might be helpful for those who wander around this topic.
Hope that helps!
Upvotes: 6
Reputation: 3075
You can create an Azure function that uses MailKit to retrieve emails and stores them in an Azure storage container.
From there you can parse the emails.
Upvotes: 1
Reputation: 403
I don't think it should be an Azure specific functionality. You can do the following: Step-1: Connect your application with Azure Active Directory through headless authentication, refer https://github.com/Azure-Samples/active-directory-java-native-headless.
Step-2: Access to Office 365 outlook emails via REST api, refer https://msdn.microsoft.com/office/office365/api/mail-rest-operations
Step-3: The job you have created can be hosted in Azure Web Job https://azure.microsoft.com/en-in/documentation/articles/websites-dotnet-webjobs-sdk-get-started/
Upvotes: 3
Reputation: 668
Upvotes: 11