如何将图像发送到asp.net,c#中的邮件。 [英] how to images are sending to mail in asp.net, c# .

查看:101
本文介绍了如何将图像发送到asp.net,c#中的邮件。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

早上好,先生,



i我在数据库中以innary格式插入图片。



然后我的问题是如何从数据库获取图像

并将图像发送到邮件,我也想从邮件中下载图像。



i尝试了一些。



string emailid =abc@gmail.com;

MailMessage mm = new MailMessage() ;

SmtpClient smtp = new SmtpClient();

mm.From = new MailAddress(emailid);

mm.Subject =文件跟踪;

mm.Body =hai;



附件imgAtt =新附件(img.ImageUrl.ToString());

//附件imgAtt = new Atta chment(Server.MapPath(+ ViewState [path]。ToString()+));

//给它一个内容id,对应于我们在正文中添加的src img标签

imgAtt.ContentId = ViewState [path]。ToString();

//将附件添加到电子邮件中

mm .Attachments.Add(imgAtt);



mm.IsBodyHtml = true;

smtp.Host =smtp.gmail.com;

smtp.EnableSsl = true;

mm.To.Add(新邮件地址(ViewState [EditVendorEmail]。ToString()));

System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential();

NetworkCred.UserName =abc@gmail.com; //写你的gmail用户名

NetworkCred.Password = abc123; //写密码

smtp.UseDefaultCredentials = true;

smtp.Credentials = NetworkCred;

smtp.Port = 587; //电子邮件的Gmail端口465或587

smtp.Send(mm);





但我有一些疑问



附件imgAtt =新附件(img.ImageUrl.ToString());



在该附件中如何发送图像(我正在从数据库中发送图像)。还可以下载从邮件发送图像。



请帮帮我...

good morning sir,

i am inserting in the images in bynary format in database.

then my question is how to get the images from database
and send that images to mail,and also i want download that images form mail also.

i was tryed some like .

string emailid = "abc@gmail.com";
MailMessage mm = new MailMessage();
SmtpClient smtp = new SmtpClient();
mm.From = new MailAddress(emailid);
mm.Subject = "File Tracking";
mm.Body = "hai";

Attachment imgAtt = new Attachment(img.ImageUrl.ToString());
// Attachment imgAtt = new Attachment(Server.MapPath("" + ViewState["path"].ToString() + ""));
//give it a content id that corresponds to the src we added in the body img tag
imgAtt.ContentId = ViewState["path"].ToString();
//add the attachment to the email
mm.Attachments.Add(imgAtt);

mm.IsBodyHtml = true;
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true;
mm.To.Add(new MailAddress(ViewState["EditVendorEmail"].ToString()));
System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential();
NetworkCred.UserName = "abc@gmail.com";//write your gmail user name
NetworkCred.Password = "abc123";// write pass word
smtp.UseDefaultCredentials = true;
smtp.Credentials = NetworkCred;
smtp.Port = 587; //Gmail port for e-mail 465 or 587
smtp.Send(mm);


but i have some doubt in that

Attachment imgAtt = new Attachment(img.ImageUrl.ToString());

in that attachment how to send images (i am geting images from database).and also download sending images from mail.

pls help me ...

推荐答案

你必须要把图像保存在一个不起眼的位置,以便可以通过发送邮件中提供的链接在任何网络邮件上查看。



它会有所帮助

电子邮件中的嵌入图像 - ASP.NET,C# [ ^ ]
You must have to save the image on an obscure location, so that it can be viewed on any webmail via link provided in the sent mail.

it would help
Embed image in Email - ASP.NET , C#[^]


Avinash是对的,首先您需要将二进制数据保存在图像泡沫中的特定位置,然后您可以将该图像附加到您的电子邮件中。你也可以参考下面的文章:

控制在ASP.NET中显示二进制图像 [ ^ ]
Avinash is right, first you need to save the binary data on a specific location in the foam of a image, then you can attach that image to your email. You can also refer below article:
Control to Display Binary Images in ASP.NET[^]


这篇关于如何将图像发送到asp.net,c#中的邮件。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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