SmtpClient class, SmtpClient
SmtpClient class
Allow applications to send emails using Simple Mail Transfer Protocol (SMTP.
Namespace: System.net. mail
Attribute
ClientCertificates: Specifies the certificate to use to establish a Secure Socket Layer (SSL) connection.
Credentials: gets or sets the credential used to authenticate the sender.
DeliveryFormat: gets or
call
useDefaultCredentials: Gets or sets a Boolean value that controls whether DefaultCredentials is sent with the request
Method
Dispose ()
Sends a quit message to the SMTP server, gracefully ends the TCP connection, and frees all resources for the SmtpClient class used by the current instance
Dispose (Boolean)
Sends a quit message to the SMTP server, ends the TCP connection gracefully, frees all the reso
The mail sending function is used in a recent project. This is different from the method used to send emails for a previous project. Previously, information about the emails to be sent was inserted into a database table on the server. The database checks newly added records and sends emails. That is, I only need to insert records into a database. This email sending function uses the smtpclient in the Microsoft system. net. Mail namespace to send messa
Today, I sent a mail to the mailbox smtpclient. The MailServer on the shelf is normal, but the MailServer on the other side is lost. It is found that the mailbox certificate appears, but the Outlook mail is normal, if no result is found, use the wireshark to check whether the smtpclient is different from the one sent by outlook. Finally, use reflector to find out how to set the authentication method.
This
. Net has greatly improved the mail. smtpclient function since 2.0. It is easy to send emails. However, the US lacks the ability to save the email content as an EML file.
In fact, smtpclient and mailmessage have implemented this function, but this function is nonpublic and invisible outside the space.
Use reflector to decompile system. net. Mail. smtpclient. You
Objective There are many ways to send mail, such as sending mail via the. Net Framework's built-in SmtpClient, using an open source project Lumisoft.net, and so on, and here's how to use SmtpClient under the System.Net.Mail namespace to send mail. First, the Mail sending process For example, a use 163 mailbox to send mail to B (QQ mailbox). First, a will mail through the SMTP (Simple Mail Transfer Prot
The procedure is this:
Copy Code code as follows:
static void Main (string[] args)
{
SmtpClient client = new SmtpClient ();
Client. Host = "localhost";
MailAddress from = new MailAddress ("from@test.com");
MailAddress to = new MailAddress ("to@test.com");
MailMessage message = new MailMessage (from, to);
Client. Send (message);
Console.ReadLine ();
}
The
ASP. NET series: SmtpClient and asp. netsmtpclient for unit testing
When SmtpClient is used to send an Email, we can create an ISmtpClient interface and a SmtpClientWrapper adaptation class. In the unit test, we can perform Mock or custom FackeSmtpClient for ISmtpClient, however, the Facke SMTP Server of nDumbster provides us with a more intuitive and simple way to perform unit tests. You can search for nDu
In the previous mailmessage saved as an EML file (C # + smtpclient), we used the Reflection Method to call system. net. mailwriter, the internal object of mail, implements saving mailmessage content as an EML file.
Through the previous implementation, I learned how to use reflection and played a role in attracting others.
Today, I occasionally saw the last code and found anotherNew WorldTo save the EML file, it becomes very simple. First, go back to t
ProgramYes:
CopyCode The Code is as follows: static void main (string [] ARGs)
{
Smtpclient client = new smtpclient ();
Client. Host = "localhost ";
Mailaddress from = new mailaddress ("from@test.com ");Mailaddress to = new mailaddress ("to@test.com ");Mailmessage message = new mailmessage (from, );
Client. Send (Message );
Console. Readline ();}
When running, the message "unable to connect b
Use the smtpclient class to send simple text emails, but cannot send emails containing attachments.To a receiver, it is a built-in JDK package, so it is more universal.The javamail package provides excellent functions to write any powerful email.System.
Source code.Function: JSP routine. use JSP to send an email.
%>Send emailRecipient address: Sender address: Subject: Letter content: Enter required options
// Obtain parametersString to = request. getp
For the first time, I used this method to send an email. For example, I used my live mailbox to send an email to my QQ mailbox.
The steps for sending an email using smtpclient will not be discussed. You can find too many information on the Internet. Here are some notes:
If the email content is HTML, set mailmessage. isbodyhtml to true so that the email can be correctly read in HTML format.
The reference resource in HTML uses CID: XXX. XXX is the cont
When sending email using smtpclient, we can create ismtpclient interfaces and Smtpclientwrapper adaptation classes, mock or custom fackesmtpclient ismtpclient in unit tests, But Ndumbster's Facke SMTP Server provides us with a more intuitive and straightforward way to unit test. You can search for ndumbster through NuGet , which uses netdumbster. 1.IEmailSender interface Public Interface iemailsender{ void SendMail (stringfromstringstring string
Refer to my blog post for a souvenir, especially the hash code-use SMTP to send emails in. net.
Reference and sort out chinafcl
In smtpclient, only the email address, password, and SMTP server address are provided. How can I test whether the email address and password are correct? (Similar to the test connection function of the mail client)
Private bool checksmtp (string smtpserver, int port, string username, string password){Tcpclient = new tcpclient
. NET since 2.0, has greatly improved the function of mail.smtpclient, for the e-mail, can be very comfortable. However, the drawback is not to provide the ability to save the content of the message as a EML file
In fact, SmtpClient and MailMessage have implemented this function, but this function is nonpublic, for the space outside, not visible.
Using Reflector to decompile the System.Net.Mail.SmtpClient you can see:
In the Send (MailMessage) me
In the previous MailMessage save as a eml file (c#+smtpclient), we used the Reflection (Reflection) method to invoke the System.Net.Mail internal object Mailwriter implemented the MailMessage is saved as a eml file.
Through the last implementation, mainly to learn reflective reflection use of ideas, play a role in it, is
Today, occasionally saw the last code, and found a new continent, so that the work of saving the eml file, become unusually simple
We can see that the outlook API is called in C # To initiate a meeting. This can be fully implemented using SMTP. The code used in my project is as follows:
For. net, it is very easy to send emails from 2.0. In addition,Alternateview,You can use the
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.