PowerTCP Mail for .NET | Create and Send an Email SMTP Code Example

See all PowerTCP Mail for .NET Code Examples

Create and Send an Email Example

This example demonstrates creating an email with text, HTML, and an attachment, and sending it to an SMTP server.

 

Smtp smtp1 = new Smtp();
//Create message to send
MailMessage message = new MailMessage();
message.To = "recipient@smtpServer.com";
message.From = "sender@smtpServer.com";
message.Subject = "Here is your file";
message.Text = "Please see the attached file.";
message.Html = "<body><p>Please see the attached file.</p></body>";

message.Attachments.Add(new Attachment("C:\\MyFiles\\myAttachment.zip"));

//Set session parameters
smtp1.Session.RemoteEndPoint = new Dart.Mail.IPEndPoint("mySmtpServer", Smtp.GetDefaultPort(smtp1.Session));
smtp1.Session.Username = "myUsername";
smtp1.Session.Password = "myPassword";

//Connect to the server and authenticate
mySmtp.Connect();
mySmtp.Authenticate();
//Send message and logout
smtp1.Send(message);
smtp1.Close();

 

 

To download a trial please visit the PowerTCP Mail for .NET product page.