problem sending Email message includes a picture

asp.net , csharp , .net fourms Toulouse, France
  • 11 years ago

    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);
    }
    
  • 11 years ago

    hi asafok,

    This can be due to the fact that you need to specify the full path of the image i.e. try to mention the full url path of the image, your................. http://sitename/img/LogoWeb.jpg

    Regards,

    Royal

  • 11 years ago

    hi asafok,

    This can be due to the fact that you need to specify the full path of the image i.e. try to mention the full url path of the image, your................. http://sitename/img/LogoWeb.jpg

    Regards,

    Royal

  • 11 years ago

    Another option would be to host the image on some image hosting site like photo bucket and embed the image url in your code...

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“If Java had true garbage collection, most programs would delete themselves upon execution.” - Robert Sewell