Sending Mail Query and To Someone's ID
Sending Mail Query and To Someone's ID
using System.Net.Mail; protected void Button1_Click(object sender, EventArgs e) { MailMessage msg = new MailMessage(); msg.To.Add(new MailAddress(txtTo.Text)); msg.From =new MailAddress(txtFrom.Text); msg.Subject = txtSubject.Text; msg.Body = txtMail.Text; Label1.Text = "Sending....."; SmtpClient smtp = new SmtpClient(); smtp.Host = "smtp.gmail.com"; smtp.Credentials=new System.Net.NetworkCredential("[email protected]","qawsedrftg"); smtp.EnableSsl = true; smtp.Timeout = 50000; smtp.Send(msg); //SmtpMail.SmtpServer = "localhost"; //SmtpMail.Send(msg); Label1.Text = "<b><i>Sent Mail ( " + txtSubject.Text + " ) <br><br> To : " + txtTo.Text + "</i></b>"; }
2. SENDING MAIL TO SOMEONES ID WITH ATTACHMENTS protected void Button1_Click(object sender, EventArgs e) { MailMessage msg = new MailMessage(); msg.To.Add(new MailAddress(txtTo.Text)); msg.From = new MailAddress(txtFrom.Text); msg.Subject = txtSubject.Text; msg.Body = txtMail.Text; Label1.Text = "Sending....."; msg.IsBodyHtml = true;
//Attach file using FileUpload Control and put the file in memory stream if (FileUpload1.HasFile) { msg.Attachments.Add(newAttachment(FileUpload1.PostedFile.InputStrea m, FileUpload1.FileName)); }
SmtpClient smtp = new SmtpClient(); smtp.Host = = "smtp.gmail.com"; smtp.Credentials=new System.Net.NetworkCredential("[email protected]","qawsedrftg"); smtp.EnableSsl = true; smtp.Timeout = 50000; smtp.Send(msg);
//SmtpMail.SmtpServer = "localhost"; //SmtpMail.Send(msg); Label1.Text = "<b><i>Sent Mail ( " + txtSubject.Text + " ) <br><br> To : " + txtTo.Text + "</i></b>"; }
SmtpClient mailClient = new SmtpClient("smtp.gmail.com", 587); mailClient.EnableSsl = true; NetworkCredential cred = new NetworkCredential("[email protected]", "rajeev@123"); mailClient.Credentials = cred; mailClient.Send(txtemail.Text, "[email protected]", txtname.Text, body); Label1.Text = "Your message has been sent." + "</Br>" + "Team will contact to you." + "</Br>" + "Thank you....";
} catch { Label1.Text = "Sorry there is some problem try after some time........!!"; }