Original article: http://blog.joycode.com/dotey/archive/2005/01/15/43113.aspx
ASP. NET forums email sending
In forums, email sending is required in many places, such as email registration, password retrieval, and email subscription.
Add a new postCodeThe process is very slow. Each time a post is added, the applicationProgramFirst, make sure that there are no repeated posts, format the post content and emoticon images, Mark and index them. If necessary, add the post to the corresponding queue to check the attachment validity, after the post is finally sent, an email notification will be sent to the subscription user. Obviously, too much work is done here. Indexing a post is a very time-consuming operation. In addition, the built-in system. Web. Mail function must be connected to the SMTP server and send emails in sequence. When the number of subscribers for a specific post or topic increases, the execution time of the post will grow.
Not every request requires indexing emails. Therefore, forums adopts centralized batch processing and only indexes 25 posts at a time or sends emails every five minutes. The timer part describes the timer application in Asp.net forums in my previous blog.
In ASP. NET, mail sending is very easy. Generally, SMTP servers are required, but some SMTP servers (such as smtp.163.com) in free mailboxes require account and password verification. Add the following content to the filds set of the mailmessage object:
Message. Fields. Add ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1 ");
// Basic Authentication
Message. Fields. Add ("http://schemas.microsoft.com/cdo/configuration/sendusername", txtusername. Text );
// Set the SMTP server Logon account (for example, your 163.com mailbox account)
Message. Fields. Add ("http://schemas.microsoft.com/cdo/configuration/sendpassword", txtpassword. Text );
// Set the SMTP server logon password (for example, your 163.com mailbox account password)
However, you must pay attention to one problem when using the free SMTP server, that is, the account that sends the email (that is, the message. from) must be the same as the account used to log on to the SMTP server. Otherwise, the CDO object cannot be found.
Sample Code:
Sample email sending code