Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET image email
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:
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 18-Feb-13 19:31pm
Edited 18-Feb-13 19:33pm
v3
Comments
ridoy at 19-Feb-13 2:49am
   
So what is the problem?what is your question?
shajarian_lover at 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)

  Print Answers RSS
0 OriginalGriff 230
1 PIEBALDconsult 150
2 DamithSL 125
3 Andreas Gieriet 90
4 Jochen Arndt 90
0 OriginalGriff 5,790
1 DamithSL 4,601
2 Maciej Los 4,012
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,195


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 19 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100