It is really easy to send e-mails using the System.Net.Mail. Below C# code demonstrates more details...
If you want to send an email using button click event, then you can do this as below...
protected void btnSubmit_Click(object sender, EventArgs e)
{
try
{
MailMessage message = new MailMessage(FromTextBox.Text, ToTextBox.Text, SubjectTextBox.Text, MessageTextBox.Text);
SmtpClient emailClient = new SmtpClient("SMTPSERVER");
emailClient.Send(message);
Status.Text = "Message Successfully Sent";
}
catch (Exception ex)
{
Status.Text = ex.ToString();
}
After writing the above code, you should configure Web.config file to send e-mails as below...
<>
<>
<>
< networkhost="mail.inzeek.com">
port="25"
userName=sahan@inzeek.com
password=mailto:password=sahan@inzeek.com />
< / smtp >
< / mailSettings >
< / system.net>
0 comments:
Post a Comment