using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Net; using System.Net.Mail; namespace EmailFunctionlaity { public partial class Email : Form { public Email() { InitializeComponent(); } //All Variable Declarations String senderAddress = string.Empty; String receiveraddress = string.Empty; String emailSubject = string.Empty; String emailMessageText = string.Empty; MailMessage mail = new MailMessage(); SmtpClient client = new SmtpClient("smtp.gmail.com",587); private void btnEmail_Click(object sender, EventArgs e) { try { //Get the Values of Controls senderAddress = txtSenderEmail.Text; receiveraddress = txtReceiverEmail.Text; emailSubject = txtSubject.Text; emailMessageText = txtMessageBody.Text; //Pass the Values mail.From = new MailAddress(senderAddress, "xxxxxxxxxx", System.Text.Encoding.UTF8); mail.To.Add(receiveraddress); mail.Subject = emailSubject; mail.Body = emailMessageText; client.UseDefaultCredentials = false; client.Credentials = new NetworkCredential("xxxxxxx@gmail.com", "xxxxxx"); client.EnableSsl = true; client.Send(mail); System.Windows.Forms.MessageBox.Show("Email Sent Successfully"); } catch (Exception mailException) { System.Windows.Forms.MessageBox.Show("Message Not Sent ,Error: " + mailException.Message); throw; } finally { } } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)