Click here to Skip to main content
15,074,394 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I'm used this code to send an Email Via embed images into body, and prevent from 'Display images below' http://cnetiran.com/net/capture.jpg[^] on target Emails
this is my code:
C#
using System;
using System.Collections;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Text;
using System.IO;
using System.Web.Services;
using System.Globalization;
using System.Net.Mail;
using System.Net.Mime;
using System.Net;

public partial class SendMail : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void Send(object sender, EventArgs e)
    {
        string subject = "CNet";
        string body = "";
        string from = "from";
        string password = "pwd";
        string server = "mail.npgnet.ir";
        string to = "r.ghafari@npg.ir";

        try
        {
            MailMessage mail = new MailMessage();
            mail.To.Add(to);
            mail.From = new MailAddress(from, subject);
            mail.Subject = "Test with Image";
            string Body = "Welcome to codedigest.com!!<br><BR>Online resource for .net articles.<BR><img alt=\"\" hspace=0 src=\"cid:imageId\" align=baseline border=0 >";

            AlternateView htmlView = AlternateView.CreateAlternateViewFromString(Body, null, "text/html");
            LinkedResource imagelink = new LinkedResource(Server.MapPath(".") + @"\pic.gif", "image/gif");
            imagelink.ContentId = "imageId";
            imagelink.TransferEncoding = System.Net.Mime.TransferEncoding.Base64;
            htmlView.LinkedResources.Add(imagelink);
            mail.AlternateViews.Add(htmlView);
            SmtpClient smtp = new SmtpClient();
            smtp.Port = 25;
            smtp.Host = server;
            smtp.Credentials = new NetworkCredential(from, password);
            //smtp.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
            smtp.Send(mail);
        }
        catch (Exception ex)
        {
            Response.Write(ex.Message);
        }
    }
}
Posted
Updated 18-Feb-13 18:33pm
v3
Comments
ridoy 19-Feb-13 2:49am
   
So what is the problem?what is your question?
shajarian_lover 19-Feb-13 5:26am
   
i want to prevent from display this Question on users mail, please check the following link and see the image.

http://cnetiran.com/net/capture.jpg

actually, without the user click on the 'Display images below', the images that embed into mail body, can be seen.

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