Skip to content
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

Unable to cast object of type 'MimeKit.TextPart' to type 'MimeKit.MessagePart' #5

Open
p231970 opened this issue Jan 27, 2017 · 5 comments

Comments

@p231970
Copy link

p231970 commented Jan 27, 2017

I have this
System.InvalidCastException: Unable to cast object of type 'MimeKit.TextPart' to type 'MimeKit.MessagePart'.
at MailBounceDetector.BounceDetectResult..ctor(MimeMessage message, MimeEntity deliveryNotification, MessageDeliveryStatus deliveryStatus, MimeEntity undeliveredMessagePart)
at MailBounceDetector.StandardBounceDetector.Detect(MimeMessage message)
at MailBounceDetector.BounceDetector.Detect(MimeMessage message)

@p231970
Copy link
Author

p231970 commented Jan 27, 2017

I think issue is in file BounceDetectResult.cs on line 182
look this screenshot http://prntscr.com/e12wlv

@rgl
Copy link
Owner

rgl commented Jan 27, 2017

Please, create a (failing) unit test that triggers this behavior.

@p231970
Copy link
Author

p231970 commented Jan 27, 2017

I am new to GitHub so sorry for maybe wrong editing. I hope you'll find all my proposed changes in few patches

@ToddHedenstrom
Copy link

I'm running into the same issue. In debugging down to this, the UndeliveredMessagePart does not contain a member of 'Message', so the exception is thrown. I'd like to help out with this, but haven't got any idea how to create a failing unit test. I have a couple of these bounces in a folder on an inbox, I can forward them to you- they are AOL bounces.

For the time being, I've just commented this segment out, as I'm not interested in the UndeliveredMessageId, but I know this isn't something that's a good option for most.

@edinj
Copy link

edinj commented Aug 17, 2017

In addition to ToddHedenstrom's comment I added extension method:

public static bool HasMethod(this object objectToCheck, string methodName)
{
var type = objectToCheck.GetType();
return type.GetMethod(methodName) != null;
}

And changed line 179 to:

if (UndeliveredMessagePart != null && UndeliveredMessagePart.HasMethod("Message"))

Now works well with message id.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants