1
votes

Problem - Not able to retreive the email address from the attached signed email

((MimeKit.MessagePart)item).Message.To

Here is the code, the saved attachments does not have the email address; but only friendly name -

                    if (fileattachment.Name == "smime.p7m")
                    {
                        // Load & read 'smime.p7m' 
                        fileattachment.Load();

                        using (MemoryStream memoryStream = new MemoryStream(fileattachment.Content))
                        {
                            MimeMessage mimeMessage = MimeMessage.Load(ParserOptions.Default, memoryStream);

                            foreach (var bodyPart in mimeMessage.BodyParts)
                            {
                                //HTML
                                if (!bodyPart.IsAttachment)
                                    continue;

                                if (bodyPart is MessagePart)
                                {
                                    //Subject is file name
                                    var fileName = ((MimeKit.MessagePart)bodyPart).Message.Subject + ".eml";
                                    var rfc822 = (MessagePart)bodyPart;

                                    if (string.IsNullOrEmpty(fileName))
                                        fileName = "attached-message.eml";

                                    using (var stream = File.Create(fileName))
                                        rfc822.Message.WriteTo(stream);
                                }
                                else
                                {
                                    var part = (MimePart)bodyPart;
                                    var fileName = part.FileName;

                                    using (var stream = File.Create(fileName))
                                        part.Content.DecodeTo(stream);
                                }
                            }


                        } //MemoryStream

                    }

Thanks in advance

1
I don't see in your code where you are trying to get the To addresses? Also, what does the raw header look like? - jstedfast
From VS QuickWatch, To Property value has {"LastName, FirstName (...)"} where Address Property has the same value and Name property has "" - Abraham V K
That’s not what I asked... look at the raw message - save it to a file if you have to. - jstedfast

1 Answers

0
votes

If your Message is of type IMessageSummary you can get the recipient this way

string recipient = Message.Envelope.To.ToString();