Want to become a Vibe Coder? Join Vibe Coding Training here
x
C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Send mail through ASP.NET
WhatsApp
Darin
Aug 23
2015
1.1
k
0
0
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Net.Mail;
namespace
WebApplication1 {
public
partial
class
Frm_ForgotPassword: System.Web.UI.Page {
protected
void
Page_Load(
object
sender, EventArgs e) {}
protected
void
Button1_Click(
object
sender, EventArgs e) {
try
{
string
Senderid =
"
[email protected]
"
;
// Your(Sender's) Email ID
string
SenderPassword =
"********"
;
// Your Password
string
Reciever_id = TextBox1.Text;
// Reciever's Email ID
SmtpClient smtp =
new
SmtpClient() {
Host =
"smtp.gmail.com"
,
Port = 587,
EnableSsl =
true
,
DeliveryMethod = SmtpDeliveryMethod.Network,
Credentials =
new
System.Net.NetworkCredential(Senderid, SenderPassword),
Timeout = 30000,
};
MailMessage message =
new
MailMessage(Senderid, Reciever_id,
"SUBJECT"
,
"BODY "
);
// (SUBJECT = Subject of the mail)
// (BODY = Message or body)
smtp.Send(message);
Response.Write(
"Mail Sent Successfully"
);
}
catch
(Exception ex) {
ex.Message.ToString();
}
}
}
}
Note:
Only the subject and the body changes as per application. You can integrate this code for Email Verification, Forgot Password, etc.
ASP.NET
Mail
Up Next
Send mail through ASP.NET