Community discussion forum

problem sending Email message includes a picture

  • 5 months 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 = "from@address.co.il";
    string toAddress = "To@address.co.il";
    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);
    }
    
    Post was edited on 19/06/2009 05:43:09 Report abuse
  • 5 months 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

  • 5 months 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

  • 5 months 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).

Want to stay in touch with what's going on? Follow us on twitter!