Java mail, java mail

Source: Internet
Author: User

Java mail, java mail
Email sending Applet:

Import java. util. properties; import java. util. export; import javax. mail. session; import javax. mail. transport; import javax. mail. internet. internetAddress; import javax. mail. internet. mimeMessage; import javax. mail. internet. mimeMessage. recipientType; public class Main {// sender private static String user = ""; // password private static String pass = ""; // recipient private static String to = ""; // topic private static String subject = ""; // content private static String content = ""; // initialize the session information private static Properties props = new Properties (); static {// mail sending protocol props. setProperty ("mail. transport. protocol "," smtp "); // SMTP Mail Server props. setProperty ("mail. smtp. host "," smtp.263.net "); // SMTP Mail Server default port props. setProperty ("mail. smtp. port "," 25 ");} public static void main (String [] args) throws Exception {sendTextEmail ();} public static void sendTextEmail () throws Exception {// The input retrieves the response info = new response (System. in); System. out. println ("account:"); user = info. nextLine (); System. out. println ("Password:"); pass = info. nextLine (); System. out. println ("recipient email:"); to = info. nextLine (); System. out. println ("topic:"); subject = info. nextLine (); System. out. println ("email content:"); content = info. nextLine (); // creates a Session session = Session. getDefaultInstance (props); // create MimeMessage message = new MimeMessage (session); // set the sender message. setFrom (new InternetAddress (user); // sets the mail subject message. setSubject (subject); // set the recipient message. setRecipient (RecipientType. TO, new InternetAddress (to); // sets the message content. setText (content); // Save the message. saveChanges (); // obtain Transport = session. getTransport (); transport. connect (user, pass); // send the email transport. sendMessage (message, message. getAllRecipients (); transport. close ();}}

 

Related Article

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.