ASP.NET - mail not send - Asked By msakt on 28-Jun-12 04:26 AM

i have smtp host and port no which smtp s mail send from local application...

but is not working in server..no error occure....
but mail send message is display


Jitendra Faye replied to msakt on 28-Jun-12 04:31 AM
Use this code and let me know

protected void yourButton_Click(object sender, EventArgs e)
  {
    
    string strMailContent = "Welcome new user";
    string fromAddress = "yourname@yoursite.com";
    string toAddress = "newuser@hisdomain.com";
    string contentId  = "image1";
    string path = Server.MapPath(@"images/Logo.jpg"); // my logo is placed in images folder
    MailMessage mailMessage = new MailMessage( fromAddress, toAddress );
    mailMessage.Bcc.Add("inkrajesh@hotmail.com"); // put your id here
    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("<html><body><img src=cid:companylogo/><br></body></html>" + strMailContent, null, MediaTypeNames.Text.Html);
    av1.LinkedResources.Add(logo);
 
 
    mailMessage.AlternateViews.Add(av1);
    mailMessage.IsBodyHtml = true;
    SmtpClient mailSender = new SmtpClient("localhost"); //use this if you are in the development server
        mailSender.Send(mailMessage);
     
    }