I am making a windows form to capture image from laptop and send it to phone through email or whatsapp or any other social networking site. Though I got the capturing image code, I couldn't find the code for sending the image. Please help.
Asked
Active
Viewed 19 times
1 Answers
0
You can send email with image with this code:
using (var client = new SmtpClient())
{
MailMessage newMail = new MailMessage();
newMail.To.Add(new MailAddress("you@your.address"));
newMail.Subject = "Test Subject";
newMail.IsBodyHtml = true;
var inlineLogo = new LinkedResource(Server.MapPath("~/Path/To/YourImage.png"));
inlineLogo.ContentId = Guid.NewGuid().ToString();
string body = string.Format(@"
<img src=""cid:{0}"" />
", inlineLogo.ContentId);
var view = AlternateView.CreateAlternateViewFromString(body, null, "text/html");
view.LinkedResources.Add(inlineLogo);
newMail.AlternateViews.Add(view);
client.Send(newMail);
}

Samuel Tulach
- 1,319
- 13
- 38
-
an System.InvalidOperationException exception is occuring at client.Send(newMail); how to handle it ? – Siddharth Rawat Jun 10 '17 at 08:23