Using System;
Using System.Net;
Using System.Net.Mail;
Using System.Text;
Namespace Sendmaildemo
{
Class Program
{
static void Main (string[] args)
{
SmtpClient client = new SmtpClient ("smtp.goodix.com");
MailAddress from = new MailAddress ("[Email protected]", "the Address this Mail Send from", Encoding.UTF8);
Constructs a recipient Address object
MailAddress to = new MailAddress ("[Email protected]", "the Address this Mail Send to", Encoding.UTF8);
Construct a Message object for an email
MailMessage message = new MailMessage (from, to);
Add message subject and content
Message. Subject = "test message subject";
Message. BODY = "test message body, It ' s Just a test!";
Set information for a message
Client. Deliverymethod = Smtpdeliverymethod.network;
If the server supports a secure connection, set the secure connection to true.
Client. Enablessl = false;
Set the user name and password.
Client. useDefaultCredentials = false;
string username = "[email protected]";
String passwd = "******";
User login Information
NetworkCredential mycredentials = new NetworkCredential (username, passwd);
Client. Credentials = mycredentials;
Send mail
Client. Send (message);
Prompt to send successfully
Console.WriteLine ("Sent successfully! ");
Console.readkey ();
}
}
}
Simple Mail-Sending program