Here we mainly use Gmail. The reason is that when I use a Gmail mailbox to send emails, I encounter a small difficulty. When I use a mailbox such as 163, you have not encountered this problem.
In ASP. net2.0, sending mail is very simple. We mainly use several classes from the namespace system. net. Mail, mailmessage and smtpclient.
Core
Code Is very concise, as follows:
Copy code Code: string to = "Enter the recipient's email address here ";
String
( -)}}Finally, the information obtained in the previous step to do some formatting to enhance the readability of the email, and then send an email with smtpclient. Here is O365 's mailbox to send email, SMTP server is ' smtp.office365.com ', port is 587$EmailBody =@ () # Format the email body$emailbody+="""Content-type""content=""text/html; charset=iso-8859-1""/>"$EmailBody+="""#FFFFFF""style=""font-size:small; font-family:tahoma; color: #000000"">"$
Here we mainly use Gmail, the reason is because, I use Gmail mailbox to send mail, encountered a small difficulty, and the use of 163 mailbox, did not encounter this problem.
In asp.net2.0, sending mail is very simple, we mainly use several classes from the namespace System.Net.Mail, MailMessage and SmtpClient.
The core code is very concise, as follows:
Copy Code code as follows:
String to = "Fill in the recipient's email address here";
S
Case Cheng
The message content call picture format is:
The service-side code for sending the message is:
SmtpClient the object//code to send the message is omitted
Copy Code code as follows:
System.Net.Mail.MailMessage MailMessage = new System.Net.Mail.MailMessage ();
Mailmessage.from= "sender's mailbox";
MAILMESSAGE.TO.ADD ("Recipient mailing List");
MAILMESSAGE.CC.ADD ("CC's Mailing List");
Mailmessage.subject = Subject;
Req.getremotehost ();
}
%>
Out.print ("In General,lao Lee are not baddie");
%>
If browser has closed cookies, how do I open the session in JSP?
You can use the URL rewrite as follows:
hello1.jsp
Integer num = new integer (100);
Session.putvalue ("num", num);
String URL =response.encodeurl ("hello2.jsp");
%>
Hello2.jsphello2.jsp
Integer i= (integer) session.getvalue ("num");
Out.println ("Num value in the session is" +i.intvalue ());
%>
Can I send email in JSP?
You can use Sun's dedicated pack
This article describes how to embed the email content into an image in. net. For more information, seeThe format of the image called by the mail content in routine 1 is the server code for sending the mail is: SmtpClient, the object for sending the mail, and the Code omitted is as follows: system. net. mail. mailMessage mailMessage = new System. net. mail. mailMessage (); mailMessage. from = "sender's mailbox"; mailMessage. to. add ("recipient email
Note: I was planning to use Sina ,(SMTP.Sina.com), but after testing, I feel this is very unstable. So I switched to the SMTP service of Gmail, and it felt very stable and fast. Record it to help later!
Method 1Bytes ------------------------------------------------------------------------------------------------------// Using system. net. mail;Mailmessageage message = new mailmessageage ();Message. From = new mailaddress ("User@gmail.com", "Your displayname ");Message. to. Add (New mailaddress
Sometimes the traditional solution of email verification is required for projects:
Public void sendresetpasswordemail (string email ){
Mailaddress from = new mailaddress ("XXX@126.com", "Mercury"); // enter the email address and display name
Mailaddress to = new mailaddress (email, email); // enter the recipient address and name of the email.
// Set the Sending address and Receiving address. The Receiving address can be multiple
Mailmessage mail = new mailmessage ();
Mail. From = fro
();// Set the mail formatMail. bodyencoding = system. Text. encoding. utf8;// Whether it is in HTML FormatMail. isbodyhtml = true;// Set the mail sending levelMail. Priority = mailpriority. High;
// Set the attachmentInt F = lfile. count;For (Int J = 0; j {Mail. attachments. Add (new attachment (lfile [J]);}
Mail. deliverynotificationoptions = deliverynotificationoptions. onsuccess;
Smtpclient client = new smtpcl
This article mainly introduces the use of C # to send custom HTML-formatted messages, detailed introduction of the method of sending HTML-formatted messages, interested to understand.
To send an HTML-formatted message, set the Isbodyhtml property of the MailMessage object to True.
The class MailMessage under namespace System.Net.Mail.
Using System.Net.Mail;
Messages sent in HTML format have been implemented in the Hovertreetop project and sent successfully.
Depends on the Hovertreeemail class o
the user name is set to IIS.
Make the following settings:
The related code is as follows:
Code
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->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
scripts must be pre-compiled. In addition, the setting of readonlyvariables and readwritevariables variables can be directly selected in the subsequent selection dialog box. These improvements are much more convenient. After the settings are complete, you can click the compile script to use the familiar C # to complete the mail sending operation.Note that we need to introduce system. net. then, use smtpclient to send emails through the specified emai
Note: I was planning to use Sina (smtp.sina.com), but after testing, I felt this was very unstable. So I switched to Gmail's SMTP service and felt very stable and fast. Record it to help later!
Method 1Bytes ------------------------------------------------------------------------------------------------------// Using system. net. mail;Mailmessageage message = new mailmessageage ();Message. From = new mailaddress ("User@gmail.com", "Your displayname ");Message. to. Add (New mailaddress ("To@gma
; // key point. An ID value is obtained here.// Message. attachments. Add (Attachment); // you can add multiple attachments.
Smtpclient client = new smtpclient ();Client. Host = strsmtpserver; // set the host name or IP address of the SMTP transactionClient. Port = intport; // port numberClient. usedefacrecredentials = true;Client. deliverymethod = smtpdeliverymethod. Network;Client. enablessl = true; // Af
you cannot directly access the built-in JSP objects, but pass through the parameter method. As follows: Lt %!Public String howBadFrom (HttpServletRequest req ){HttpSession ses = req. getSession ();...Return req. getRemoteHost ();}% Gt Lt %Out. print ("in general, lao lee is not baddie ");% Gt Lt % = howBadFrom (request) % gt
12. If the BROWSER has disabled COOKIES, how can I enable SESSION in JSP to track them?Use the URL to rewrite it, as shown below:Hello1.jsp Lt % @ page session = "true"
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.