Java do not log in to send mail noreply

Source: Internet
Author: User

Recently encountered a problem at work:

Customers need to have our system send them email, but don't give us a user password.

This leads to a problem, that is, generally we use the SMTP way to send e-mail, e-mail must be logged in, although you can modify the sender's mailbox name. But still need to login AH.

On this question, I began to explore. Search all the major domestic websites have no examples.

Here is the code that I have here to solve the problem:

  

1  Public Static voidSend () {2           //Recipient ' s email ID needs to be mentioned.3String to = "[Email protected]";4 5           //Sender ' s email ID needs to be mentioned6String from = "[Email protected]";7 8           //assuming you is sending email from localhost9String host = "xxx.xxx.36.3";Ten  One           //Get System Properties AProperties Properties =system.getproperties (); -  -           //Setup Mail Server theProperties.setproperty ("Mail.smtp.host", host); -  -           //Get The default Session object. -Session session =Session.getdefaultinstance (properties); +  -           Try{ +          //Create a default MimeMessage object. AMimeMessage message =NewMimeMessage (session); at  -          //Set from:header field of the header. -Message.setfrom (Newinternetaddress (from)); -  -          //Set to:header field of the header. - message.addrecipient (Message.RecipientType.TO, in                       Newinternetaddress (to)); -  to          //Set subject:header Field +Message.setsubject ("This is the Subject line!"); -  the          //Now set the actual message *Message.settext ("This is actual message"); $ Panax Notoginseng          //Send Message - transport.send (message); theSYSTEM.OUT.PRINTLN ("Sent message successfully ..."); +}Catch(Messagingexception Mex) { A mex.printstacktrace (); the           } +}

Using this method can be achieved, do not log in to send anonymous mail, the perfect solution to my problem, I hope to yimeimei helpful.

Thank you ~

Java do not log in to send mail noreply

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.