0% found this document useful (0 votes)
9 views

Sending Mail Query and To Someone's ID

The document provides code samples for sending emails using C# and .NET. 1. The first section shows how to send an email to a recipient with sender details, subject, and body populated from text boxes. It uses SMTP to send through Gmail. 2. The second section expands on the first by adding the ability to attach a file from an upload control to the email. 3. The third section shows how to receive emails on a Gmail account, by sending an email from a contact form with sender and recipient addresses swapped to receive the message. It handles errors if the send fails.

Uploaded by

Neeraj Gupta
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Sending Mail Query and To Someone's ID

The document provides code samples for sending emails using C# and .NET. 1. The first section shows how to send an email to a recipient with sender details, subject, and body populated from text boxes. It uses SMTP to send through Gmail. 2. The second section expands on the first by adding the ability to attach a file from an upload control to the email. 3. The third section shows how to receive emails on a Gmail account, by sending an email from a contact form with sender and recipient addresses swapped to receive the message. It handles errors if the send fails.

Uploaded by

Neeraj Gupta
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

1.

SENDING MAIL TO SOMEONES 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>"; }

3. RECEIVING QUERY (OR EMAIL) ON YOUR GMAIL ID


try { string body = ""; body += "\n Title:-" + title; body += "\n Name:-" + txtname.Text; body += "\n SurName:-" + txtsurname.Text; body += "\n Address:-" + txtaddress.Text; body += "\n Postal Code:-" + txtpostalcode.Text; body += "\n E-Mail:-" + txtemail.Text; body += "\n Telephone No:-" + txttelephone.Text; body += "\n Mobile No:-" + txtmobile.Text; body += "\n Inquire or Book:-" +inqBook; SmtpClient smtp = new SmtpClient();

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........!!"; }

You might also like