-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parse inbound emails in "raw" format #488
Comments
I think the ideal implementation would be to keep the single Parse method and internally detect which setting was used. That way code doesn't need to change when updating settings on the SendGrid side. It could detect the content by looking for the We've been using "Send Raw" disabled but recently noticed that certain attachment types can be dropped. MSG files for example won't come through from SendGrid. We're talking with SendGrid's support on that issue but enabling Send Raw does make the attachment come through. Ironically I've had two different support contacts say
|
hummmmm... Automatically detect the format of the payload based on the presence or absence of the "email" parameter is a very good suggestion: developers wouldn't have the make a decision which method of the StrongGrid parser to invoke, it wouldn't matter which format they configure in the SendGrid app, they could even switch back and forth between the two formats (the SendGrid UI allows you to do this very easily) and StrongGrid would transparently parse the content appropriately without any change in the developer's code. I like it!
Thank you for sharing your experience, The fact that some attachments are missing when you turn off the "Raw" format makes it critical that we support the raw format. I'll start working on it and post a beta as soon as possible. |
Published beta package |
Thanks for the fast turnaround on this! Unfortunately we can't use that beta package (or latest on master) right now because we use it in an Azure Function app (in process) which can't use v7.0.0 versions of Microsoft.Extension packages without moving to isolated. Once we can update to .Net 8 it should also fix the issue. If you could update the .Net 6 version to use v6.0 for Microsoft.Extensions.Logging and possibly System.Text.Json that would help us update to the latest version. That said I pulled your updates into an extension method to test it in our project and have a couple notes:
For the first two items here is my updated version of ConvertMime
|
Is there a reason to prefer "in process" rather that "isolated"? As I understand it, the "in process" mode condemns you to being at the mercy of the the version of certain nuget packages referenced by the Azure environment (such as System.Text.Json and Microsoft.Extensions.Logging for example) which may conflict with the version of same packages referenced by 3rd party parckages (StongGrid being an example of such a 3rd party but this problem is not limited to StrongGrid). I'm sure you're aware that a few people have raised issues in this repo to make me aware of this problem and that the conclusion is that switching to "isolated" mode would instantly solve this problem. There's probably a legitimate reason for preferring "in process" that I'm simply not aware of.
Downgrading the version of these packages referenced by StrongGrid could probably solve the problem in the short term but this is a never ending cycle caused by the Azure environment not keeping up with new releases of the referenced packages. As far as I know, this whole problem could be completely avoided by simply using Azure's "isolated" mode. I say "simply" but I realize nothing is ever as simply as it seems!!! 😄
Thanks for the suggestions.
Excellent! Thank you for sharing. I'll try to send myself an email with an attached MSG and/or EML attachment to more closely mimic your scenario. Also, if you could share your payload, that would help me test your scenario as closely as possible, |
@dandenton I sent myself a test email with an attached EML and I experienced the casting problem you alluded to and your I have published another beta version In an effort to help you test this beta version, I have downgraded the references to System.Text.Json and Microsoft.Extensions.Logging but I want to make crystal clear that I will not publish the final version with these downgraded references mainly because it would bring back nasty serialization problems (see #463 and #476 for some details). |
You're absolutely right about In-Proc vs Isolated. Isolated should be the way to go but when you're dealing with projects from < 2020 sometimes it's hard to get time to update, especially since it didn't cause any issues until .Net 7.0. No worries about not being able to revert them. I'll try to get the update to isolated prioritized higher. Changes look good although I just realized the file name for attached EML/MSG is using the subject which could be blank. It might be a good idea to give it some sane default like Another question I thought of is if StrongGrid should take a dependency on MimeKit vs MimeKitLite. Lite seems to work for this use and it basically the same as MimeKit just without the crypto dependencies. |
Good idea.
I wasn't aware of their "lite" package. Let me look into it... |
First of all, I was referencing MailKit when I should have referenced MimeKit. I made the switch to MimeKitLite which works perfectly for our situation. Thanks for pointing me to this package. I also implemented your idea of ensuring attachments have a name even when the subject line is blank. I improved upon your suggestion by defaulting to $"Attachment{index}" to ensure the name is reasonably unique even if multiple attachments have a blank subject line. Published one more beta package 0.102.0-parse-raw-inboun0023 to my Feedz.io nuget repository. |
🎉 This issue has been resolved in version 0.102.0 🎉 The release is available on: Your GitReleaseManager bot 📦🚀 |
When developers configure the inbound parse feature in their SendGrid account they must specify if they want to use the "raw" format or not. Currently, StrongGrid's webhook parser is not compatible with the raw format but some developers don't realize that and they enable the "raw" format. Also, there's some verbiage in SendGrid's app that implies that it's preferable to enable the "raw" format which understandably leads some developers to enable it.
Over the years this has caused a number of problems such as:
InboundEmail model missing properties (ParseInboundEmailWebhookAsync) #446
Inbound Parse Message-ID and In-Reply-To #257
ParseInboundEmailWebhook() is not reading attachments #176
Value cannot be null. (Parameter 'source')
Value cannot be null. (Parameter 'source') on ParseInboundEmailWebhookAsync (.NET 5) #417
Duplicate field in section
Unable to parse SendGrid Example Default or Example Raw payloads - "Duplicate field in section" error #400
InboundParse #375
"Duplicate field in section" MultipartParseException in Email Parse #346
can't parse default message from sendgrid #333
Email parse event error #202
I am wondering if it would make sense to offer a way to parse inbound emails in raw format. Something along the lines of:
The developer would be responsible to chose between
ParseRawInboundEmailWebhookAsync
andParseInboundEmailWebhookAsync
depending on whether they enabled the raw format or not.I'm looking for feedback, does anybody think it would be valuable? Is there a reason developers prefer one format over the other? If we move forward with this idea, would anybody be able and willing to help beta test this new functionality?
The text was updated successfully, but these errors were encountered: