Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

c# how to send a email

// in the beginning of the file
using System.Net;
using System.Net.Mail;
MailAddress to = new MailAddress("charles@westminster.co.uk");
MailAddress from = new MailAddress("piotr@mailtrap.io");
MailMessage message = new MailMessage(from, to);
message.Subject = "Good morning, Charles";
message.Body = "Charles, Long time no talk. Would you be up for lunch in Soho on Monday? I'm paying.;";
SmtpClient client = new SmtpClient("smtp.server.address", 2525)
{
    Credentials = new NetworkCredential("smtp_username", "smtp_password"),
    EnableSsl = true
// specify whether your host accepts SSL connections
};
// code in brackets above needed if authentication required
try
{
  client.Send(message);
}
catch (SmtpException ex)
{
  Console.WriteLine(ex.ToString());
}
Source by mailtrap.io #
 
PREVIOUS NEXT
Tagged: #send #email
ADD COMMENT
Topic
Name
8+1 =