Sending Emails from asp.net application using c#.net
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Data.OleDb;
using System.Web.Security;
using System.Data;
using System.Configuration;
using System.Net.Mail;
public partial class Default5 : System.Web.UI.Page
{
protected void btEnvoyer_Click(object sender, EventArgs e)
{
MailMessage message = new MailMessage();
SmtpClient smtpClient = new SmtpClient();
// try
// {
MailAddress fromAddress = new MailAddress(tbDestinataire.Text);
message.From = fromAddress;
message.To.Add(tbDestinataire.Text);
message.Subject = tbObjet.Text;
message.IsBodyHtml = true;
message.Body = tbMessage.Text;
// We use gmail as our smtp client
if (LstMail.Text == "@yahoo.fr")
{
smtpClient.Host = "smtp.mail.yahoo.com";
smtpClient.Port = 25;
smtpClient.EnableSsl = false;
}
if (LstMail.Text == "@gmail.com")
{
smtpClient.Host = "smtp.gmail.com";
smtpClient.Port = 587;
smtpClient.EnableSsl = true;
}
// smtpClient.UseDefaultCredentials = true;
smtpClient.Credentials = new System.Net.NetworkCredential(tbExpediteur.Text, tbPassword.Text);
smtpClient.Send(message);
// }
// catch
// {
// }
}
}
Comments
Post a Comment