Click here to Skip to main content
15,860,861 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
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
Updated 2-Oct-12 19:12pm
v3
Comments
Abhijit Parab 3-Oct-12 1:04am    
what error it shows?

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
:)
 
Share this answer
 
Comments
Shambhoo kumar 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900