Javaweb Mailbox Send (mailbox client configuration)

Source: Internet
Author: User
Tags mail account

This is the local mailbox server,

Code Execution conditions:

1. mailbox server, password S4XN

Mailbox Server Configuration:

1): Installation

2): Open server

The red part is the default account, no processing

3) System Settings "Click on the tool" Server Settings "

4) Create an account

2. Email client, can be downloaded to official website:

1. Installation of the mailbox client

Incoming and outgoing mail server: localhost

3. Mail.jar Bag

4.Util Tool Class

 PackageCom.study.mail;Importjava.util.Properties;ImportJavax.mail.Authenticator;ImportJavax.mail.Message;Importjavax.mail.MessagingException;Importjavax.mail.PasswordAuthentication;Importjavax.mail.Session;ImportJavax.mail.Transport;Importjavax.mail.internet.AddressException;Importjavax.mail.internet.InternetAddress;ImportJavax.mail.internet.MimeMessage;ImportJavax.mail.internet.MimeMessage.RecipientType; Public classmailutils {//Email:email address, subject mailbox subject, EMAILMSG mailbox information Public Static voidSendMail (String email,string Subject, string emailmsg)throwsaddressexception, messagingexception {//1. Create a program and mail server session object sessionsProperties Props=NewProperties (); Props.setproperty ("Mail.transport.protocol", "SMTP");//protocol for sending mailProps.setproperty ("Mail.host", "localhost");//server address for sending mailProps.setproperty ("Mail.smtp.auth", "true");//Specifies that validation is true//creating validatorsAuthenticator auth =NewAuthenticator () { Publicpasswordauthentication getpasswordauthentication () {return NewPasswordauthentication ("Tom", "123456");//e-mail account authentication            }        }; Session Session=session.getinstance (props, auth); //2. Create a message that corresponds to the content of the messageMessage message =NewMimeMessage (session); Message.setfrom (NewInternetAddress ("[email protected]");//Set Sendermessage.setrecipient (recipienttype.to,NewInternetAddress (email));//set the sending method and receiverMessage.setsubject (subject);//set the subject of the message//Message.settext ("This is an activation email, please <a href= ' # ' > Click </a>"); //set the contents of a messageMessage.setcontent (emailmsg, "Text/html;charset=utf-8"); //3. Create transport to send messagestransport.send (message); }}

Test class:

 Package Com.study.mail; Import javax.mail.MessagingException; Import javax.mail.internet.AddressException;  Public class sendmailtest {    publicstaticvoidthrows  Addressexception, messagingexception {        mailutils.sendmail ("[email protected]", "Test Mail", "This is a test message");}    } 



Javaweb Mailbox Send (mailbox client configuration)

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.