将图像从数据库嵌入到电子邮件正文中

编程入门 行业动态 更新时间:2024-10-27 16:25:13
本文介绍了将图像从数据库嵌入到电子邮件正文中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

解决方案

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

ContentType ct = 新 ContentType(); ct.MediaType = MediaTypeNames.Image.Jpeg; ct.Name = " MyPic.Jpg" ; 附件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);

更多推荐

将图像从数据库嵌入到电子邮件正文中

本文发布于:2023-11-09 03:07:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1571227.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文中   图像   电子邮件   数据库

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!