将图像从数据库嵌入到电子邮件正文中 [英] Embed images in email body from database

查看:69
本文介绍了将图像从数据库嵌入到电子邮件正文中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我已将图像上传到数据库中.我想在电子邮件正文中嵌入相同的图像并将其发送.我怎样才能做到这一点.我发现了许多谈论使用服务器中的文件夹将图像嵌入到电子邮件正文中的链接(链接的资源和备用视图).请让我知道我该怎么做

解决方案

从DB读取图像时,您将获得一个字节数组.您可以将转换为MemoryStream的字节数组添加为附件,如下所示:

 ContentType ct =  ContentType();
ct.MediaType = MediaTypeNames.Image.Jpeg;
ct.Name = " ;
附件att = 附件( MemoryStream(myPicBytes),ct); 


Hi,

I have uploaded images in to the database. i would like to embed same images in the email body and send it. how can i do that. i found many links which talk about embedding images in the email body using folder in the server(Linked resource and alternate views). pls let me know how can i do this

解决方案

You get a byte array when you read image from DB. You can you byte array converted to MemoryStream to add as an attachment, like this:

ContentType ct = new ContentType();
ct.MediaType = MediaTypeNames.Image.Jpeg;
ct.Name = "MyPic.Jpg";
Attachment att = new Attachment(new MemoryStream(myPicBytes), ct);


这篇关于将图像从数据库嵌入到电子邮件正文中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆