这是代码。。。
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;
using System.IO;
public partial class TestAttachSend : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSend_Click(object sender, EventArgs e)
{
if (fuImage.HasFile && fuImage.PostedFile.ContentType == System.Net.Mime.MediaTypeNames.Image.Jpeg)
{
SmtpClient emailClient = new SmtpClient();
MailMessage EmailMsg = new MailMessage();
EmailMsg.To.Add(txtEmail.Text.Trim());
EmailMsg.From = new MailAddress(txtEmail.Text.Trim());
EmailMsg.Subject = "Attached Image";
EmailMsg.Body = "Image is attached!";
MemoryStream imgStream = new MemoryStream();
System.Drawing.Image img = System.Drawing.Image.FromStream(fuImage.PostedFile.InputStream);
string filename = fuImage.PostedFile.FileName;
img.Save(imgStream, System.Drawing.Imaging.ImageFormat.Jpeg);
EmailMsg.Attachments.Add(new Attachment(imgStream, filename, System.Net.Mime.MediaTypeNames.Image.Jpeg));
emailClient.Send(EmailMsg);
lblSent.Visible = true;
}
}
}
这段代码可以正常工作。但当你打开电子邮件中的附加图像时,它会显示"文件为空"
有人能看到我哪里出错了吗???
此外,我想使用多种图像格式(gif,png)。但我不知道该怎么做。
尝试进行
imgStream.Seek(0L, SeekOrigin.Begin);
在将CCD_ 1传递给CCD_。