I created an email web application, how to view and save the attached files?
I am using OpenPop , a third party dll, I can send emails with attachments and read emails without attachments.
This works great:
Pop3Client pop3Client = (Pop3Client)Session["Pop3Client"]; // Creating newPopClient int messageNumber = int.Parse(Request.QueryString["MessageNumber"]); Message message = pop3Client.GetMessage(messageNumber); MessagePart messagePart = message.MessagePart.MessageParts[1]; lblFrom.Text = message.Headers.From.Address; // Writeing message. lblSubject.Text = message.Headers.Subject; lblBody.Text=messagePart.BodyEncoding.GetString(messagePart.Body);
This second part of the code displays the contents of the attachment, but it is only useful if it is a text file. I need to be able to save the attachment. Also, the bottom of the code that I have here is recording the body of my message, so if I receive an attachment, I cannot view the body of the message.
if (messagePart.IsAttachment == true) { foreach (MessagePart attachment in message.FindAllAttachments()) { if (attachment.FileName.Equals("blabla.pdf")) {
Pomster
source share