Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7751849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:39:11+00:00 2026-06-01T11:39:11+00:00

Ok, I don’t know what else to do. This code worked perfectly fine a

  • 0

Ok, I don’t know what else to do. This code worked perfectly fine a week ago when I wrote and tested it. Then I embedded it into my program and realised I kept getting exceptions. Everything seems normal. The sender address is legit. The recipient addresses I used to test it are legit. What is wrong? I’m so frustrated:

private String outgoingMailServer = "smtp.mail.yahoo.com";

boolean debug = true;

            //set the host outgoing mail smtp server.
            Properties properties = new Properties();
            properties.put("mail.smtp.host", outgoingMailServer);
            properties.put("mail.smtp.auth", "true");

            Authenticator authenticator = new SMTPAuthentication();
            Session session = Session.getDefaultInstance(properties, authenticator);

            session.setDebug(debug);

            //create a message session
            Message msg = new MimeMessage(session);

            //set the addresses, to and from
            InternetAddress fromAddress;
            fromAddress = new InternetAddress(emailFromAddress);
            msg.setFrom(fromAddress);

            //since mail can be sent to more than one recipient, create loop
            //to add all addresses into InternetAddress, addressTo.
            //InternetAddress[] toAddress = new InternetAddress[recipients.length];
            InternetAddress[] toAddress = new InternetAddress[recipients.size()];
            for (int i = 0; i < recipients.size(); i++) {
                toAddress[i] = new InternetAddress(recipients.get(i));
            }
            msg.setRecipients(Message.RecipientType.TO, toAddress);

            //set the subject and content type
            msg.setSubject(emailSubject);
            msg.setContent(actualMessage, "text/html; charset=utf-8");

            //send the email
            Transport.send(msg);

The exception is thus:

javax.mail.SendFailedException: Invalid Addresses;
  nested exception is:
    com.sun.mail.smtp.SMTPAddressFailedException: 554 5.7.1 <blank@yahoo.com>: Sender address rejected: Access denied

    at com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1835)
    at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1098)
    at javax.mail.Transport.send0(Transport.java:195)
    at javax.mail.Transport.send(Transport.java:124)
    at internalLogicEngine.LogicEngine.sendReminder(LogicEngine.java:4282)
    at testPackage.Test.main(Test.java:169)
Caused by: com.sun.mail.smtp.SMTPAddressFailedException: 554 5.7.1 <blank@yahoo.com>: Sender address rejected: Access denied

    at com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1733)
    ... 5 more

Any help would be most appreciated. Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T11:39:12+00:00Added an answer on June 1, 2026 at 11:39 am

    Finally figured out a work-around (though I still can’t understand why there’s a problem in the first place, seeing as the codes used to work. Anyways…)

    private String outgoingMailServer = "smtp.mail.yahoo.com";    
    boolean debug = false;
    
    //set the host outgoing mail smtp server.
    Properties properties = new Properties();
    properties.put("mail.smtp.host", outgoingMailServer);
    properties.put("mail.smtps.auth", "true");
    
    Authenticator authenticator = new SMTPAuthentication();
    Session session = Session.getDefaultInstance(properties, authenticator);
    session.setDebug(debug);
    
    //create a message session
    Message msg = new MimeMessage(session);
    
    //set the addresses, to and from
    InternetAddress fromAddress;
    fromAddress = new InternetAddress(emailFromAddress);
    msg.setFrom(fromAddress);
    
    //since mail can be sent to more than one recipient, create loop
    //to add all addresses into InternetAddress, addressTo.
    //InternetAddress[] toAddress = new InternetAddress[recipients.length];
    InternetAddress[] toAddress = new InternetAddress[recipients.size()];
    for (int i = 0; i < recipients.size(); i++) {
        toAddress[i] = new InternetAddress(recipients.get(i));
    }
    msg.setRecipients(Message.RecipientType.TO, toAddress);
    
    //set the subject and content type
    msg.setSubject(emailSubject);
    msg.setContent(actualMessage, "text/html; charset=utf-8");
    
    //send the email
    Transport transport = session.getTransport("smtps");
    transport.connect(outgoingMailServer, 465, emailUserName, emailPassword);
    transport.sendMessage(msg, msg.getAllRecipients());
    transport.close();
    
    //email sent
    //note, this does not necessarily mean the email was delivered. The
    //sysetm has no control over that
    emailSent = true;
    

    You’ll find that the main difference between the codes in the question and these ones are:

    Transport.send(msg);
    

    and

    Transport transport = session.getTransport("smtps");
    transport.connect(outgoingMailServer, 465, emailUserName, emailPassword);
    transport.sendMessage(msg, msg.getAllRecipients());
    transport.close();
    

    Turns out, a Transport object had to be created and connected using the proper credentials (port number, username, password, and mail server).

    Also, I did a process of elimination and found out that as long as you have this:

    Transport transport = session.getTransport("smtps");
    transport.connect(outgoingMailServer, 465, emailUserName, emailPassword);
    transport.sendMessage(msg, msg.getAllRecipients());
    transport.close();
    

    you don’t need this:

    Authenticator authenticator = new SMTPAuthentication();
    Session session = Session.getDefaultInstance(properties, authenticator);
    

    The above could as well be:

    Session session = Session.getDefaultInstance(properties, null);
    

    Anyway, that’s the answer. You can also alter this answer for gmail. Just be sure to change the outgoing mail server to gmail’s, as well as the from email address, username and password, and you’ll be just fine 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

(Don't know if this is strictly on-topic, but I don't see any better Stack
Don't know if this has been asked before, so point me to another question
Don't know if anyone can help me with this or if it's even possible.
I don't know: if this works. if it's a good idea. what it is
I don't know if this question is trivial or not. But after a couple
Don't know if this is the right place to ask this, but I will
Don't know where else to ask, but from one day to the other my
Don't know why this is happening, but after submitting a form via JS (using
Don't know what to do with this error. How to add data in SQL
Don't know if this is an eclipse specific problem but whenever I declare a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.