1

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

  • 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 Nov 19 '20 at 16:14
  • From VS QuickWatch, To Property value has {"LastName, FirstName \(...\)"} where Address Property has the same value and Name property has "" – Abraham V K Nov 23 '20 at 14:57
  • That’s not what I asked... look at the raw message - save it to a file if you have to. – jstedfast Nov 23 '20 at 19:32

1 Answers1

0

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

string recipient = Message.Envelope.To.ToString();
ɐsɹǝʌ ǝɔıʌ
  • 4,440
  • 3
  • 35
  • 56
  • Not able to cast the Message to IMessageSummary. We are creating the MimeMessage from a stream of bytes. This is an attachment which is signed email. TopEmail -->Attachment(SignedEmail). We are trying to retrieve the email properties(To, Sender, ReplyTo), but actual email address is missing, while the friendly name is available. Please share any example links... – Abraham V K Nov 19 '20 at 10:16