Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
how to snd email in submit button
Posted

This is code to send mail:
C#
using System.Net;
using System.Net.Mail;

var fromAddress = new MailAddress("from@gmail.com", "From Name");
var toAddress = new MailAddress("to@example.com", "To Name");
const string fromPassword = "fromPassword";
const string subject = "Subject";
const string body = "Body";

var smtp = new SmtpClient
           {
               Host = "smtp.gmail.com",
               Port = 587,
               EnableSsl = true,
               DeliveryMethod = SmtpDeliveryMethod.Network,
               UseDefaultCredentials = false,
               Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
           };
using (var message = new MailMessage(fromAddress, toAddress)
                     {
                         Subject = subject,
                         Body = body
                     })
{
    smtp.Send(message);
}

Add it on button click.
 
Share this answer
 
Dude, there are loads of examples online, try google.
 
Share this answer
 
Comments
Prasad_Kulkarni 27-Jul-12 6:04am    
5'ed
Kenneth Haugland 27-Jul-12 6:11am    
Thanks :), wonder what dude gave me a 1 ;)
Prasad_Kulkarni 27-Jul-12 6:14am    
It happens all around with no reason.

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