Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How send mail with contact information in asp.net...
Posted

This questions have many answers on code project already
Code Project Results
 
Share this answer
 
This code is for gmail server.

C#
using system;
using system.net.mail; 

protected void btnSend_Click(object sender, EventArgs e)
    {
        MailMessage msg = new MailMessage();
        MailAddress mailfrom = new MailAddress("from@gmail.com");
        msg.To.Add( "to@example.com");
        msg.From = mailfrom;
        msg.CC.Add("some@example.com");
        msg.Bcc .Add("some@gmail.com");
        msg.Body = "name:"+txtname.Text+"\n"+"Address:"+txtAddress.Text+"\n"+"phoneno:"+txtPhone.Text+"\n";
        msg.Subject = "sending code for email sending";
        SmtpClient smtp = new SmtpClient("localhost");
        smtp.Host = "smtp.gmail.com";
        smtp.Credentials = new System.Net.NetworkCredential("username@gmail.com", "mypassword");
        smtp.Send(msg);
        

    }

If your having smtp in your system then you can use this code
smtp.Host="localhost";Instead of (smtp.Host = "smtp.gmail.com";)
no need of using credentials here.
 
Share this answer
 
v2
sendEmail("Test Subject", "me@mail.com", "user1@mail.com,user2@mail.com,user3@mail.com", "Body of email", "", "",null);
 
public static bool sendEmail(string strSubject, string strFrom, string strTo, string strBody, string strCc, string strBcc,string displayName)
{
System.Net.Mail.SmtpClient Mail = new System.Net.Mail.SmtpClient();
Mail.Host = clsCommon.value("SMTPServer").ToString();
 
 
string username = null;
string Password = null;
 
Mail.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
username = "MailUserName";
Password = "MailPassword";
System.Net.NetworkCredential basicAuthenticationInfo = new System.Net.NetworkCredential(username, Password);
 
Mail.UseDefaultCredentials = false;
Mail.Credentials = basicAuthenticationInfo;
 

 
System.Net.Mail.MailMessage myMail = new System.Net.Mail.MailMessage();
myMail.Subject = strSubject;
 
myMail.From = new System.Net.Mail.MailAddress(strFrom,displayName);
myMail.To.Add(new System.Net.Mail.MailAddress(strTo));
if (!string.IsNullOrEmpty(strCc))
{
myMail.CC.Add(new System.Net.Mail.MailAddress(strCc));
}
if (!string.IsNullOrEmpty(strBcc))
{
myMail.Bcc.Add(new System.Net.Mail.MailAddress(strBcc));
}
 
myMail.IsBodyHtml = true;
myMail.Body = strBody;
try
{
 
Mail.Send(myMail);
 
 
return true;
}
catch (Exception ex)
{
ex.Message.ToString();
return false;
}
}
 
Share this answer
 
 
Share this answer
 

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