Simple
Mail Transfer Protocol (SMTP)
Simple Mail Transfer Protocol (SMTP) is a TCP/IP protocol used in sending and receiving e-mail. Most of the e-mail systems that send mail over the Internet use SMTP to send messages from one server to another. The messages can then be retrieved with an e-mail client using either POP or IMAP.
message.IsBodyHtml = true;
{
};
try
}
{
Simple Mail Transfer Protocol (SMTP) is a TCP/IP protocol used in sending and receiving e-mail. Most of the e-mail systems that send mail over the Internet use SMTP to send messages from one server to another. The messages can then be retrieved with an e-mail client using either POP or IMAP.
SMTP Class in C#: MailMessage class is part of the namespace System.Net.Mail and it is used to create the email messages that are sent to the SMTP Server. The delivery of the message will be taken care by the SmtpClient Class.
SMTP Class Properties:- Host: Server URL for SMTP
- EnableSsl: True or False.
- Port: Port Number of the SMTP server
- Credentials: Valid login credentials for the SMTP server (the email address and password).
- UseDefaultCredentials: When we set to True then that specifies to allow authentication based on the credentials of the account used to send emails.
S.No | Mail Server | SMTP Server( Host ) | Port Number | SSL |
1 | Gmail | smtp.gmail.com | 587 | YES |
2 | Outlook | smtp.live.com | 587 | YES |
3 | Office365.com | smtp.office365.com | 587 | YES |
4 | Zoho Mail | smtp.zoho.com | 587 | YES |
5 | Mandril | smtp.mandrillapp.com | 587 | YES |
6 | SendGrid | Smtp.sendgrid.net | 587 | YES |
Sending
an HTML email in C#
Sample project is available at this Github location
using System.Net;using System.Net.Mail;var to = new MailAddress("fromaddress@example.com");var from = new MailAddress("toaddress@example.com");var message = new MailMessage(from, to);message.Subject = "Test Email Subject";message.Body = "<h1> Test Email Message</h1>";message.IsBodyHtml = true;
SmtpClient client = new SmtpClient("smtp.gmail.com", 587){
Credentials = new NetworkCredential("smtp_username","smtp_password"), EnableSsl = true};
try
{ client.Send(message);}
catch (SmtpException ex){
Console.WriteLine(ex.ToString());}
Comments
Post a Comment