【发布时间】:2016-01-14 10:30:15
【问题描述】:
我的方法使用 SMTP 中继服务器发送电子邮件。
一切正常(电子邮件已发送),除了附件(图像)以某种方式压缩/不存在并且无法从电子邮件中检索。
方法如下:
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;
}
}
- 上传的图片不为空。
- ContentLength 为 1038946 字节(大小正确)。
但是,正在发送的电子邮件包含带有正确文件名的图像作为附件,尽管它的大小为 0 字节。
我错过了什么?
【问题讨论】:
标签: c# asp.net smtp email-attachments