It is mandatory to use SMTP authentication when sending emails through our servers. Below is a sample C# code snippet demonstrating how to implement SMTP authentication. You can modify it as needed for your specific setup.
using System;
using System.Net;
using System.Net.Mail;
class Program
{
static void Main()
{
SmtpClient smtpClient = new SmtpClient();
MailMessage message = new MailMessage();
// Sender Email Address & Display Name
MailAddress fromAddress = new MailAddress("from@from.com", "From Name");
// SMTP Server Hostname or IP Address
smtpClient.Host = "mail.yoursite.com"; // Alternatively, use mail server IP
// SMTP Port (Default: 25)
smtpClient.Port = 25;
// SMTP Authentication Credentials
NetworkCredential info = new NetworkCredential("smtpuser@yoursite.com", "smtp-password");
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = info;
// Assign Sender Address
message.From = fromAddress;
// Recipient Address
message.To.Add("to@domain2.com");
// Email Subject
message.Subject = "Your subject";
// Optional: CC & BCC (Uncomment to use)
// message.CC.Add("cc@domain.com");
// message.Bcc.Add("bcc@domain.com");
// Define Email Body Format (true for HTML, false for plain text)
message.IsBodyHtml = false;
// Email Body Content
message.Body = "Body of email is here";
// Send Email
smtpClient.Send(message);
}
}
Update smtpClient.Host
with your mail server's hostname or IP.
Replace "smtpuser@yoursite.com"
and "smtp-password"
with valid SMTP credentials.
Modify "from@from.com"
, "to@domain2.com"
, and the subject/body as needed.
If using a different SMTP port (e.g., 587 for TLS or 465 for SSL), update smtpClient.Port
accordingly.
By implementing this authentication method, you ensure that emails sent through our servers are properly authenticated and delivered securely.