Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
public void SendHTMLMail()
    {
        MailMessage Msg = new MailMessage();
        MailAddress fromMail = new MailAddress("xxxxx@gmail.com");
        // Sender e-mail address.
        Msg.From = fromMail;
        // Recipient e-mail address.
        Msg.To.Add(new MailAddress("xxxxxxxx@gmail.com"));
        // Subject of e-mail
        Msg.Subject = "Send Gridivew in EMail";
        Msg.Body += "Please check below data <br /><br />";
        Msg.Body += GetGridviewData(gvUserInfo);
        Msg.IsBodyHtml = true;
        string sSmtpServer = "";
        sSmtpServer = "587";
        SmtpClient a = new SmtpClient();
        a.Host = sSmtpServer;
        a.EnableSsl = true;
        a.Send(Msg);
    }
if i execute it show error....
Posted 2-Oct-12 20:00pm
Edited 2-Oct-12 20:12pm
Mehdi Gholam249.3K
v3
Comments
Abhijit Parab at 3-Oct-12 1:04am
   
what error it shows?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Quote:
System.Net.Mail;
using System.Net;
 
var fromAddress = new MailAddress("from@gmail.com", "From Name");
var toAddress = new MailAddress("to@yahoo.com", "To Name");
const string fromPassword = "password";
const string subject = "test";
const string body = "Hey now!!";
 
var smtp = new SmtpClient
{
Host = "smtp.gmail.com",
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
Credentials = new NetworkCredential(fromAddress.Address, fromPassword),
Timeout = 20000
};
using (var message = new MailMessage(fromAddress, toAddress)
{
Subject = subject,
Body = body
})
{
smtp.Send(message);
}

 

 
try this code
 
Regard
Sham
Smile | :)
  Permalink  
Comments
shambhoo kumar at 3-Oct-12 3:39am
   
if this is helpfull to u then accept my answer.........
 
Regard
Sham
:)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 BillWoodruff 360
1 Mathew Soji 309
2 Maciej Los 270
3 DamithSL 225
4 Afzaal Ahmad Zeeshan 202
0 OriginalGriff 6,249
1 Sergey Alexandrovich Kryukov 5,853
2 DamithSL 5,183
3 Manas Bhardwaj 4,673
4 Maciej Los 3,865


Advertise | Privacy | Mobile
Web03 | 2.8.1411019.1 | Last Updated 3 Oct 2012
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