Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Add Reference:
- using System.Net;
- using System.Net.Mail;
- Code:
- string to = "ReceiverName@gmail.com";
- string from = "SenderName@gmail.com";
- MailMessage message = new MailMessage(from, to);
- message.Subject = "Using the new SMTP client.";
- message.Body = @"Using this new feature, you can send an email message from an application very easily.";
- message.Attachments.Add(new Attachment("c:\\test.txt"));
- SmtpClient client = new SmtpClient(server, 587);
- client.EnableSsl = true;
- //client.UseDefaultCredentials = true;
- client.Credentials = new NetworkCredential("UserName", "Password");
- try
- {
- client.Send(message);
- }
- catch (Exception ex)
- {
- Console.WriteLine("Exception caught in CreateTestMessage2(): {0}", ex.ToString());
- }
Add Comment
Please, Sign In to add comment