Click here to Skip to main content
15,921,793 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how to send email from asp.net page
Posted

Have a look at this Microsoft Video tutorial:
Use ASP.NET to send Email from Website[^]
 
Share this answer
 
 
Share this answer
 
Hi There are lot of results in google. However many people asking the same qn again and again. So I am giving the simple for here to try with....
C#
using System.Net.mail;

C#
MailMessage message = new MailMessage();

message.To.Add(new MailAddress("youname@yourname.com"));
message.From = new MailAddress("myname@myname.com");
message.CC.Add(new MailAddress("myfriendname@myfriendname.com"));
message.IsBodyHtml=true; // If want to sent html mail
message.Subject = "Test Subject";

message.Body = "Test Mail";

SmtpClient client = new SmtpClient("your smtp host name", 25); //replace 25 with your hosts smtp port number
client.Send(message);
 
Share this answer
 
v2
Albinabel has given a right answer but it wil not work, because you need to specify the credentials i.e username, password and secure connection before sending the mail.

Following piece of code wil let u send email, and i have also provided it with google smtp server settings, so that you can check it easily

just replace network credentials with your google username, password, for to use with google,

Or to use with some other SMTP Server, change the host name also

C#
            MailAddress mafrom = new MailAddress("mani@abc.com");
            MailAddress mato = new MailAddress("dontumindit@yahoo.com");
            MailMessage mymsg = new MailMessage(mafrom, mato);

//body of the email
            mymsg.Subject = "hy";
            mymsg.Body = "How are You";

//SMTP Settings, ihave written for google, you may write your SMTP server
            SmtpClient smptc = new SmtpClient("smtp.gmail.com", 587);
            smptc.UseDefaultCredentials = false;
            smptc.EnableSsl = true;

//Your username, password for SMTP server            
            smptc.Credentials = new NetworkCredential("username", "password");
            smptc.Send(mymsg);
 
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