Monday, January 13, 2014

Sending Mail through C# Mail Sender In C#

 private void Button_Click_1(object sender, RoutedEventArgs e)
        {

            SmtpClient client = new SmtpClient("smtp.gmail.com");
            client.Port = 587;
            client.EnableSsl = true;
            client.Timeout = 100000;
            client.DeliveryMethod = SmtpDeliveryMethod.Network;
            client.UseDefaultCredentials = false;
            client.Credentials = new NetworkCredential(
              "mailID", "password");
            MailMessage msg = new MailMessage();
            msg.To.Add("Write Message Here");
            msg.From = new MailAddress("yourmailID@gmail.com"); //replace with your email id
            msg.Subject = "Send from C#";
            msg.Body = "Testing 123";
            Attachment data = new Attachment(textBox_Attachment.Text);
            msg.Attachments.Add(data);
            client.Send(msg);
            MessageBox.Show("Successfully Sent Message.");

        }