我試圖用郵件框架爲MVC發送帶附件的emil。用附件發送電子郵件時的空文件
我可以用Postal發送電子郵件沒有問題,但是,當我嘗試發送帶附件的電子郵件時,文件變空。
這裏是我的代碼:
dynamic emailNovoOrcamento = new Email("OrcamentosServicos/NotificaNovoOrcamento");
emailNovoOrcamento.To = usuario.UsuEmail;
emailNovoOrcamento.From = "[email protected]";
emailNovoOrcamento.Subject = "Test...";
ContentType conteudo = new ContentType();
conteudo.MediaType = MediaTypeNames.Image.Jpeg;
conteudo.Name = "userPhoto.jpg";
Attachment imagemDestinatario = new Attachment(new getUserPhotoStream(usuario), conteudo);
emailNovoOrcamento.Attachments.Add(imagemDestinatario);
emailNovoOrcamento.Send();
getUserPhotoStream
是一個轉換到byte[]
一個Stream
的方法:
public MemoryStream getUserPhotoStream(byte[] photo)
{
MemoryStream imagemStream = new MemoryStream();
Image imagem;
MemoryStream imagemUsuarioStream = new MemoryStream(photo);
imagem = Image.FromStream(imagemUsuarioStream);
imagem.Save(imagemStream, ImageFormat.Jpeg);
return imagemStream;
}
}
當我通過電子郵件發送,文件大小爲0KB。
我在做什麼錯?