Knowledgebase: outmail
How do I set up outbound SMTP using the .Net SmtpClient Class?
|
|||||||||||||
Problem:How do I set up outbound SMTP using the .Net SmtpClient Class? Solution:The following example of code assumes you have already got a fully functional webserver and the .Net Framework Installed The below example of code shows you have to use outMail as the outgoing SMTP relay using the SmtpClient Class in the .Net Framework Example VB.NET code ' Create the Mail Message Dim Mail As New MailMessage ' Set the address information Mail.From = New MailAddress("myaddress@example.com") Mail.To.Add("sendingaddress@example.com") ' Set the content of the email Mail.Subject = "test email" Mail.Body = "This is an email!" ' Send the message Dim SMTP As New SmtpClient("mxXXXXXX.smtp-engine.com") SMTP.EnableSsl = False SMTP.Credentials = New System.Net.NetworkCredential("outmail-username", "outmail-password") SMTP.Port = 25 SMTP.Send(Mail) Example VB.NET code (Safer Error trapping method) ' Create the Mail Message Using Mail As New MailMessage ' Set the address information Mail.From = New MailAddress("myaddress@example.com") Mail.To.Add("sendingaddress@example.com") ' Set the content of the email Mail.Subject = "test email" Mail.Body = "This is an email!" ' Send the message Using SMTP As New SmtpClient("mxXXXXXX.smtp-engine.com") SMTP.EnableSsl = False SMTP.Credentials = New System.Net.NetworkCredential("outmail-username", "outmail-password") SMTP.Port = 25 SMTP.Send(Mail) End Using End Using Example C# code
// Create the Mail Message MailMessage
mail = new MailMessage();
// Set the address information
mail.From = new MailAddress("myaddress@example.com");
mail.To.Add("sendingaddress@example.com");
// Set the content of the email
mail.Subject = "test email";
mail.Body = "This is an email!";
// Send the message
SmtpClient smtp = new SmtpClient("mxXXXXXX.smtp-engine.com");
smtp.EnableSsl = False;
smtp.Credentials = New NetworkCredential("outmail-username", "outmail-password");
smtp.Port = 25; smtp.Send(Mail);
Summary of server details
| |||||||||||||
|