Asp.net two methods for sending emails

Source: Internet
Author: User

(Reproduced in http://www.cnblogs.com/wengyuli/archive/2010/06/03/aspnet-smtp-send-mail.html#2057232)

 

I have read some emails sent by Asp.net over the past few days. I remember that there was an SMTP server on IIS6, which can be used to send emails directly. The current development environment is Windows 7, I couldn't find it for a long time. I checked it on the network and found out that both windows 7 and Vista removed the SMTP server. Now I will summarize the two methods.

1. Use SMTP of a large website to send emails

This method is applicable to the scenario where no SMTP server is configured for the program running environment. If you want to use other smtp to send emails, you must have an smtp account. For example, if you want to use Google's SMTP server, there are three points to note: Enable SSL, port and address smtp.gmail.com.

2. Use local smtp to send emails

This method requires a local smtp server. If not, a software can be installed without an smtp server on windows 7 and vista,

Free SMTP Server,: http://www.softstack.com/freesmtp.html. this parameter is used only when the user name is set to IIS.

Make the following settings:

The related code is as follows:

 

Code

1 using System;
2 using System. Collections. Generic;
3 using System. Linq;
4 using System. Text;
5 using System. Net. Mail;
6
7 namespace IISSendMail
8 {
9 class Program
10 {
11 static void Main (string [] args)
12 {
13/* First, use Google's smtp to send emails */
14 SmtpClient client =
15 new SmtpClient ("smtp.gmail.com", 25 );
16 MailMessage msg =
17 new MailMessage ("wengyuli@gmail.com", "leonweng@qq.com", "this is the title", "this is the content ");
18 client. usedefacrecredentials = false;
19 System. Net. NetworkCredential basicAuthenticationInfo =
20 new System. Net. NetworkCredential ("username", "password ");
21 client. Credentials = basicAuthenticationInfo;
22 client. EnableSsl = true;
23 client. Send (msg );
24
25/* Second, use local smtp to send emails */
26 SmtpClient smtp =
27 new smtpclient ("localhost", 25 );
28 mailmessage message =
29 new mailmessage ("wengyuli@gmail.com", "leonweng@qq.com", "title: Test IIS mail", "content: Old Man, hello! Haha ");
30 SMTP. Send (Message );
31
32 console. writeline ("sent successfully! ");
33 console. Read ();
34}
35}
36}
37

 

 

 

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.