These two days because the company website mail can't send out , And then we studied in asp Website to send email and in The code of the website to send mail , Record the problems here .

1、 Let's talk about in the first place Send email in ,

At first it was just 126 The mailbox can send mail , Then the other 163、 Sina can't send it out , Later, I was depressed for a long time before I knew about the mailbox smtp and pop3 The service is not open by default , You need to open it manually to send mail . For example, Sina email opened smtp The service screenshot is as follows :

Other mail boxes are similar , Then we can realize the function of sending mail , The sending code is as follows :

 /// <summary>
/// C# Send E-mail
/// </summary>
public void ShowSendEmail()
string fromEmail = ""; // Sender's email address
string emailSMTPHost = ""; // mailbox SMTP The server , Used to send mail
string emailSubject = "Email Subject"; // Email subject
string emailBody = "<h1>Email Content</h1><h3> Ha ha ha , Send E-mail OK 了 !!!^_^</h3>"; // Email content
string toEmail = ""; // The email address of the object to be sent string emailName = fromEmail; // Login email user name , It can be the same as the sender's email address
string emailPwd = "********"; // Password for login email try
using (MailMessage msg = new MailMessage(fromEmail, toEmail, emailSubject, emailBody))
msg.IsBodyHtml = true; // Set whether the email content supports html Format
msg.To.Add(""); // Appending multiple recipient mailbox , Achieve mass distribution
msg.Priority = MailPriority.High; // Priority of sending mail SmtpClient mailClient = new SmtpClient(emailSMTPHost);
mailClient.UseDefaultCredentials = false; // Set whether to send with request
mailClient.Credentials = new System.Net.NetworkCredential(emailName, emailPwd); // Use secure socket layer or not (SSL) Encrypted connection . SmtpClient Use SSL, Then for true; Otherwise false. The default value is false.
mailClient.EnableSsl = true; mailClient.Send(msg); // Call the send mail method
catch (Exception ex)
// fail in send :ex.Message;
} // Send successfully

2、 And then use asp To send mail , Now after testing, there are two ways to send mail successfully

The code of the first method is as follows :

' Define how to send mail
function showSendEmail
Set objMail = Server.CreateObject("CDO.Message")
Set objCDO = Server.CreateObject("CDO.Configuration")
objCDO.Fields("") =
objCDO.Fields("")= "" ' Mail server
objCDO.Fields("") = ' Mail server default port
objCDO.Fields("") = ' timeout
objCDO.Fields("") =
objCDO.Fields("") = ""' Email address to send mail to
objCDO.Fields("") = "*****" ' Mailbox password
Set objMail.Configuration = objCDO
objMail.From = "" ' Sender , This is consistent with the email address above
objMail.Subject = "Email Subject" ' Email title
objMail.To = "" ' The recipient
objMail.HtmlBody = " hello , Test mail , How's everything going recently? ?" ' send content .
Set objMail = Nothing
Set objCDOSYSCon = Nothing
end function showSendEmail ' Calling method , Send E-mail %>

The second call JMail Component to send mail , When you call this component to send mail ,

One thing to note , Must install JMail After component , To send mail successfully ( It hasn't been installed before , Send always report missing object error )

JMail The component download path is :

' Define how to send mail 
Sub showJmail
On Error Resume Next
Dim JMail
Set JMail = Server.CreateObject("JMail.Message")
JMail.Logging = True
JMail.Charset = "gb2312"
JMail.MailServerUserName = "" ' Email login user name
JMail.MailServerPassword = "*************" ' Mailbox password
JMail.ContentType = "text/html"
JMail.Priority = 1
JMail.From = "" ' Sender's email address
JMail.FromName = "xmTan" ' Sender's name , It can be the same as the sender's email address
JMail.AddRecipient "" ' The recipient's email address
JMail.Subject = "Email Subject" ' Email subject
JMail.Body = "<h1>Email Content </h1> hello , The transmission was successful ^_^" ' Email content
JMail.Send ("") ' mailbox SMTP The server
Set JMail = Nothing
SendMail = "OK"
If Err Then SendMail = Err.Description Response.Write("<h1> Send results :"&SendMail&"</h1>")
End Sub showJmail ' Calling method , Send E-mail %>

ASP and ASP.NET Send email notes for more related articles

  1. Asp.Net Core WebApi Learning notes ( Four )-- Middleware

    Asp.Net Core WebApi Learning notes ( Four )-- Middleware This article records Asp.Net Pipe models and Asp.Net Core Of Middleware Model comparison , And add... On the basis of the previous article Mid ...

  2. ASP.NET Core 2 Learning notes ( 7、 ... and ) route

    ASP.NET Core By routing (Routing) Set up , To be defined URL Rules find corresponding behaviors : When users Request Of URL When certain rule conditions are met , Then it automatically corresponds to the corresponding behavior processing . from ASP.NET It's a frame that already exists ...

  3. ASP.NET Core 2 Learning notes ( 13、 ... and )Swagger

    Swagger It's been a long time API File generator , As long as API Upper use C# Of <summary /> File annotation label , You can create beautiful online documents , And right RESTful API Have good support . Not only support generation ...

  4. ASP.NET Core 2 Learning notes ( Twelve )REST-Like API

    Restful Almost API The standard of design , adopt HTTP Method Distinguish between new (Create). Inquire about (Read). modify (Update) And delete (Delete), abbreviation CRUD Four ways to access data , Simple and direct style ...

  5. ASP.NET Core 2 Learning notes ( Ten ) View

    ASP.NET Core MVC Medium Views Is responsible for web page display , Render the data together to UI contain HTML.CSS etc. . And it hurts Razor Syntax in *.cshtml Write the program logic of rendering picture in . This article will introduce ASP.NET Co ...

  6. sql server On the problem of adding only labels in tables C# Automatically open and close executable files ( or Close the executable file that stops interacting with the system ) ajaxfileupload Plug in upload image function , use MVC and aspx Do backstage each wrote a case Convert lowercase Arabic numerals to uppercase Chinese characters , C# WinForm In Chinese and English , A simple way to internationalize ASP.NET Core 2 Learning notes ( 6、 ... and )ASP.NET Core 2 Learning notes ( 3、 ... and )

    sql server On the problem of adding only labels in tables   Because our system time is too long , Large amount of data , The design is to use self increasing ID When we insert data, we put ID Write it in, too , We can use Turn off and turn on the self incrementing logo When it's not closed , Give me a hint ...

  7. ASP.NET Core 2 Learning notes ( One ) Start

    original text :ASP.NET Core 2 Learning notes ( One ) Start Come on, come on .NET Core Seems to replace .NET Framework,ASP.NET And then it was released .NET Core edition . Although the name is still used ASP.NET, ...

  8. ASP.Net WebForm Review the old and learn the new : Two 、ViewState And UpdatePanel explore a mystery

    The opening : After the last one <aspx Explore with server control > after , We get it aspx And the story behind the server controls . In this article, we start to walk into WebForm One of the magic weapons of maintaining state —ViewState, Get to the bottom of it . then , Again ...

  9. ASP.Net WebForm Review the old and learn the new : One 、aspx Explore with server control

    The opening : without doubt ,ASP.Net WebForm It's a cross era Web Development mode , It will WinForm The advantages of fast and convenient development mode are transplanted to Web Development , We just need to learn three steps : Drag control → Set attribute → Tie up incident , Then you can ...

  10. 【 Reprint 】ASP.Net WebForm Review the old and learn the new : One 、aspx Explore with server control

    The opening : without doubt ,ASP.Net WebForm It's a cross era Web Development mode , It will WinForm The advantages of fast and convenient development mode are transplanted to Web Development , We just need to learn three steps : Drag control → Set attribute → Tie up incident , Then you can ...

Random recommendation

  1. iOS Animation

    Layer tree . Boarding maps and layer Geometry ( One ) Tree structure of layers New technology exchange QQ Group :414971585 The Colossus has layers , Onions also have layers , Are you? ? We all have layers -- Shrek Core Animation In fact, it's a misleading life ...

  2. Realization Activity Refresh ( turn )

    Now refresh Acitivity, Just think of a few ways . For reference only , If you have a better way , Please comment . Program interface : Click on refresh view You can refresh the interface , Click on write content Can be in EditText Write automatically in ...

  3. Struts2( sixteen )Json

    One .JSON Json It's a lightweight object that exchanges data between browser and server javaSctipt Similar object operations in $(function() { var person = { "name" ...

  4. Xcode All versions of the official download and Baidu cloud disk download , Mac and IOS And Xcode Version history .

    The official download , Log in with a developer account , Suggest using Safari Browser download . Official download address : Baidu cloud disk download address : http:/ ...

  5. Sublime Text 2 Use experience

    A more detailed article : One . Preface As a front end , It is necessary to have a good development tool ...

  6. Fedora 21 install QQ International Edition

    First install the dependency package sudo yum install freetype.i686 libpng.i686 libgcc.i686 libXau.i686 Click to download wine-2012qq International Edition unzip ...

  7. [C++/CLI Programming book ][2] What is? C++/CLI Language

    For what is C++/CLI, First of all, we can simply divide the name into two parts to understand , First of all ,C++, We are familiar with the widely used object-oriented ISO International standard high level language , Also known as ISOC++, We will call it here later ISOC++ ...

  8. JAVA Basic knowledge summary : One

    One . Common sense of software development 1. What is software ? A series of computer data or instructions organized in a particular order Common software : Systems software :Windows\Mac OS \Linux Application software :QQ, A series of players ( Iqiyi , Letv , ...

  9. C# Read PDF Multi level Bookmarks

    stay PDF in , Bookmarks as an effective tool for navigation , It can help us quickly locate the specified paragraph in the document . meanwhile , Bookmarks also give you a clear idea of the structure of a document , It can also be used as a directory to some extent . about C# operation PDF Bookmarks in , In the last article, I introduced the specific ...

  10. C# entrust .

    What is a delegate . Delegation is a data type . The role of delegation . Encapsulate the changes . A delegate is a reference variable , After declaration, it is not assigned to null   So check before use is not empty . class Program { static void Ma ...