Click here to Skip to main content
15,907,913 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 ...
Posted
Updated 12-Feb-15 21:51pm
v5
Comments
Member 11166005 19-Feb-15 0:47am    
You want to attach a image or some other thing . i have code for attachment of mail. if you want i can share it
Member 10776340 20-Feb-15 4:50am    
pls sir give that code . realy i want that code.

sir my images are stored in database as a binary format.
so how to send image to mail and how to download that images from mail..

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#[^]
 
Share this answer
 
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[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900