My method sends an email using SMTP Relay Server.
Everything works fine (an email is sent), except that the attached file (image) is somehow compressed / does not exist and cannot be extracted from the email.
The method is as follows:
public static bool SendEmail(HttpPostedFileBase uploadedImage) { try { var message = new MailMessage() //To/From address { Subject = "This is subject." Body = "This is text." }; if (uploadedImage != null && uploadedImage.ContentLength > 0) { System.Net.Mail.Attachment attachment; attachment = new System.Net.Mail.Attachment(uploadedImage.InputStream, uploadedImage.FileName); message.Attachments.Add(attachment); } message.IsBodyHtml = true; var smtpClient = new SmtpClient(); //SMTP Credentials smtpClient.Send(message); return true; } catch (Exception ex) { //Logg exception return false; } }
- UploadedImage is not null.
- ContentLength - 1038946 bytes (correct size).
However, the sent e-mail contains an image as an attachment with the correct file name, although its size is 0 bytes.
What am I missing?
source share