Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Feb 04, 2013 08:02 PM by anilreddy128
Member
249 Points
887 Posts
Jan 19, 2008 12:48 PM|LINK
Hello,
How do i send mails in .net c# ?
I have been sending in classic asp for years, but not sure how to in .net
Thanks
Contributor
5455 Points
948 Posts
Jan 19, 2008 02:15 PM|LINK
Hi, Take a look at my earlier posts here: http://forums.asp.net/t/1197230.aspx This is an example in VB but you can convert to C# by using this site tool: http://labs.developerfusion.co.uk/convert/vb-to-csharp.aspx
All-Star
80367 Points
6801 Posts
Jan 21, 2008 08:42 AM|LINK
Hi,
In ASP.NET, you can use System.Net.Mail to achieve it.
Code-Behind:
Using System.Net.Mail;
public void SendEmail(string from, string to, string bcc, string cc, string subject, string body) { try { MailMessage NewEmail = new MailMessage(); NewEmail.From = new MailAddress(from); NewEmail.To.Add(new MailAddress(to)); { NewEmail.Bcc.Add(new MailAddress(bcc)); } if ((cc != null) && (cc != string.Empty)) { NewEmail.CC.Add(new MailAddress(cc)); } NewEmail.Subject = subject; NewEmail.Body = body; NewEmail.IsBodyHtml = true; SmtpClient mSmtpClient = new SmtpClient(); // Send the mail message mSmtpClient.Send(NewEmail); this.Label1.Text = "Email sent successful."; } catch { this.Label1.Text = "Email sent failed"; } } protected void Button1_Click(object sender, EventArgs e) { string from = "yourFromeMail";// like username@server.com string to = TextBox1.Text; //your To Mail string bcc = ""; string cc = ""; string subject = "text"; string body = "text"; SendEmail(from, to, bcc, cc, subject, body); }
Web.Config: <system.net> <mailSettings> <smtp> <network host="your stmp server" port="25" userName="your from email" password="your password"/> </smtp> </mailSettings> </system.net>There are more information on sending mail: http://forums.asp.net/t/971802.aspx Hope it helps.
Web.Config:
<system.net> <mailSettings> <smtp> <network host="your stmp server" port="25" userName="your from email" password="your password"/> </smtp> </mailSettings> </system.net>
There are more information on sending mail: http://forums.asp.net/t/971802.aspx
Hope it helps.
Jan 21, 2008 09:33 AM|LINK
Ok thanks,
about the system.net for the web.config file. do i need to put it under any hierarchy or at the bottom of the web.config file ?
afrika
Jan 21, 2008 09:41 AM|LINK
You can put them in <configuration>
Jan 21, 2008 10:05 AM|LINK
Ok thanks
thats what i did
Ehi
Jan 21, 2008 12:45 PM|LINK
smcoxon Hi, Take a look at my earlier posts here: http://forums.asp.net/t/1197230.aspx This is an example in VB but you can convert to C# by using this site tool: http://labs.developerfusion.co.uk/convert/vb-to-csharp.aspx
thanks Smcoxon
the conversion always gives errors. It doesnt event the vbCrLf
164 Points
65 Posts
Feb 04, 2013 08:30 AM|LINK
I am new to .net.
Plz help me what is host="your smtp server"
118 Points
48 Posts
Feb 04, 2013 08:02 PM|LINK
host="IP address of your SMTP server"
afrika
Member
249 Points
887 Posts
web mailer
Jan 19, 2008 12:48 PM|LINK
Hello,
How do i send mails in .net c# ?
I have been sending in classic asp for years, but not sure how to in .net
Thanks
smcoxon
Contributor
5455 Points
948 Posts
Re: web mailer
Jan 19, 2008 02:15 PM|LINK
Hi, Take a look at my earlier posts here: http://forums.asp.net/t/1197230.aspx This is an example in VB but you can convert to C# by using this site tool: http://labs.developerfusion.co.uk/convert/vb-to-csharp.aspx
Smcoxon
No Gem is ever polished without some friction.
Vince Xu - M...
All-Star
80367 Points
6801 Posts
Re: web mailer
Jan 21, 2008 08:42 AM|LINK
Hi,
In ASP.NET, you can use System.Net.Mail to achieve it.
Code-Behind:
Using System.Net.Mail;
public void SendEmail(string from, string to, string bcc, string cc, string subject, string body) { try { MailMessage NewEmail = new MailMessage(); NewEmail.From = new MailAddress(from); NewEmail.To.Add(new MailAddress(to)); { NewEmail.Bcc.Add(new MailAddress(bcc)); } if ((cc != null) && (cc != string.Empty)) { NewEmail.CC.Add(new MailAddress(cc)); } NewEmail.Subject = subject; NewEmail.Body = body; NewEmail.IsBodyHtml = true; SmtpClient mSmtpClient = new SmtpClient(); // Send the mail message mSmtpClient.Send(NewEmail); this.Label1.Text = "Email sent successful."; } catch { this.Label1.Text = "Email sent failed"; } } protected void Button1_Click(object sender, EventArgs e) { string from = "yourFromeMail";// like username@server.com string to = TextBox1.Text; //your To Mail string bcc = ""; string cc = ""; string subject = "text"; string body = "text"; SendEmail(from, to, bcc, cc, subject, body); }afrika
Member
249 Points
887 Posts
Re: web mailer
Jan 21, 2008 09:33 AM|LINK
Ok thanks,
about the system.net for the web.config file. do i need to put it under any hierarchy or at the bottom of the web.config file ?
afrika
Vince Xu - M...
All-Star
80367 Points
6801 Posts
Re: web mailer
Jan 21, 2008 09:41 AM|LINK
You can put them in <configuration>
afrika
Member
249 Points
887 Posts
Re: web mailer
Jan 21, 2008 10:05 AM|LINK
Ok thanks
thats what i did
Ehi
afrika
Member
249 Points
887 Posts
Re: web mailer
Jan 21, 2008 12:45 PM|LINK
thanks Smcoxon
the conversion always gives errors. It doesnt event the vbCrLf
maheshvishnu
Member
164 Points
65 Posts
Re: web mailer
Feb 04, 2013 08:30 AM|LINK
I am new to .net.
Plz help me what is host="your smtp server"
anilreddy128
Member
118 Points
48 Posts
Re: web mailer
Feb 04, 2013 08:02 PM|LINK
host="IP address of your SMTP server"
Test Engineer