SMTP, which consists of the initials of the words Simple Mail Transfer Protocol, is "Simple mail transfer (Sending) protocol". Smpt, also known as the outgoing mail server, is used to send mail. Pop3 and Imap protocols are used as incoming mail servers. SMTP mail server is useful when sending e-mails with 3rd party software.
It is necessary to install a 3rd party mail program. Outgoing and incoming mail server settings must be made and the SMTP port must be entered.
SMTP port is a port through which we send e-mail when sending e-mail. By default it is port 25. However, due to the increase in spam e-mail sending incidents, port 25 was closed and the SMTP port number was changed to port 587. You should set this port as port 587 in your 3-party mail program.
If you do not set the SMTP port number, you cannot send e-mails.
When you try to send an e-mail with a 3rd party e-mail program, a connection is first tried to be established through the account and port information you entered. Therefore, you must enter your account information and SMTP port information correctly. If we have set everything up correctly, when we write an e-mail and send it, a connection is made to our opposite SMTP server via port 587. Your authentication is done through this port. If the verification is successful, the e-mail you want to send will be sent.
Although both stmp ports perform the same operation, the main difference between them is this. While authentication is not mandatory on port 25, authentication is mandatory on port 587, thus trying to prevent spam e-mails.
Come on, let's look at this together. First of all, we need to add the System.Net.Mail reference to use Smtp. We must also add the System.Text reference to set the encoding setting for UTF8 (Encoding.UTF8). Then we need to set the Port, Host, EnableSsl (i.e. secure access), Timeout, DeliveryMethod and Credentials settings. After making these settings, we can only create the MailMessage object and complete the sending process. If we look at the codes, we can think of a code block like this.
Yes, sending e-mail in general is like this in C# and .NET. The example shown is sending an e-mail to only one user. If you want to send multiple emails. You can add code like this or make changes to the code block.
Additionally, if you want the names of the e-mail owners to appear, you can also make an arrangement like this.
You can also do the same format for your own email address, so that your title appears when you send an email.
This is how to send e-mail via SMTP in simple terms with C#.
We wish everyone good work.
We help you with your business's most critical issues and opportunities. How about getting permanent change and results together?