2
Answers

problem sending Email message includes a picture

Asaf ok

Asaf ok

15y
3.7k
1

I'm trying to send a message using the ASPX page and code c # when the goal to incorporate a picture in a message similar to many sites on the web. The searched little on Google and found all kinds of code combinations that should make the task ... actually i focused on the code listed below . if i look at the email message received I can see the picture as white square containing a red X indicates that the -HTML code is supposed to contain image but not actually covered, so that the displays the square. I'd be happy if someone could raise the subordination and write the code properly in - C # asp.net pages to send mail who can also incorporate a photo .

I used a code:

  protected void sendImg_Click(object sender, EventArgs e)
{
string strMailContent = "Welcome new user";
string fromAddress = "[email protected]";
string toAddress = "[email protected]";
string contentId = "image1";
string path = Server.MapPath(@"img/LogoWeb.jpg"); // my logo is placed in images folder
MailMessage mailMessage = new MailMessage(fromAddress, toAddress);
mailMessage.Subject = "Welcome new User";


LinkedResource logo = new LinkedResource(path);
logo.ContentId = "companylogo";
// done HTML formatting in the next line to display my logo
AlternateView av1 = AlternateView.CreateAlternateViewFromString("
" + strMailContent, null, MediaTypeNames.Text.Html);
av1.LinkedResources.Add(logo);


mailMessage.AlternateViews.Add(av1);
// mailMessage.AlternateViews.Add(imageView);
mailMessage.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient(); //use this if you are in the development server


smtp.Send(mailMessage);
}

Answers (2)