Send Email - potatoscript/csharp GitHub Wiki
What is an SMTP port
- SMTP(Simple Mail Transfer Protocol) is the basic standard that mail servers use to send email to one another across the internet.
- SMTP is also used by applications such as Apple Mail or Outlook to upload emails to mail servers that then relay them to other mail servers.
using System.Net.Mail;
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp.outlook.com");
mail.From = new MailAddress("[email protected]");
mail.To.Add("[email protected]");
mail.Subject = "Test Mail";
mail.Body = "This is for testing SMTP mail";
SmtpServer.Port = 587;
SmtpServer.EnableSsl = true;
SmtpServer.UseDefaultCredentials = false;
SmtpServer.DeliveryMethod = SmtpDeliveryMethod.Network;
SmtpServer.Credentials = new System.Net.NetworkCredential("[email protected]", "adminPassWord");
SmtpServer.Send(mail);
- An "SMTP" port refers to the specific part of the Internet address that's used to transfer email.
- The web and HTTP use port number 80. For email and SMTP, that port number is depended as below:
Port Number | Description | WHen to Use it |
---|---|---|
25 | Standard SMTP port | Often blocked by ISPs and cloud providers. |
465 | Out-of-date(deprecated)port for secure SMTP | Do not use unless absolutely necessary |
587 | Modern port for secure SMTP | The best choice for SparkPost and modern apps |
2525 | Alternative, non-standard SMTP port | An alternative in case when standard ports are not available |
Note
Set SmtpServer.EnableSsl = false;
//set to false to prevent the SmtpException: Server does not support secure connections
// that mean no need Credentials anymore