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

  • Home
  • SEARCH
  • 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 8486751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:02:24+00:00 2026-06-10T21:02:24+00:00

I am trying to write a simple mail sender class that would receive a

  • 0

I am trying to write a simple mail sender class that would receive a bunch of arguments and using those will send an email out using our Exchange 2010 server. While authentication etc. seem to work fine, I am getting the following exception when the code is actually trying to send the email (I think). I have ensured that the authentication is working and I get a transport back from the session, but still it fails. Could anyone shed some like on what I am doing wrong or missing? Thanks.

Exception:

javax.mail.MessagingException: [EOF]
       at com.sun.mail.smtp.SMTPTransport.issueCommand(SMTPTransport.java:1481)
       at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1512)
       at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1054)
       at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:634)
       at javax.mail.Transport.send0(Transport.java:189)
       at javax.mail.Transport.send(Transport.java:140)
       at com.ri.common.mail.util.MailSender.sendHTMLEmail(MailSender.java:75)
       at com.ri.common.mail.util.MailSender.main(MailSender.java:106)

Relevant code:

import java.util.Properties;

import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;


public class MailSender
{
    public static void sendHTMLEmail( String fromEmailId, String toEmailId, String host, String hostUserName,
            String hostPassword, String mailSubject, String mailBody )
    {
        // Get system properties.
        Properties props = System.getProperties();
        // Setup mail server
        props.put( "mail.transport.protocol", "smtp" );
        props.put( "mail.smtp.host", host );
        props.put( "mail.smtp.auth", "true" );

        final String hostUName = hostUserName;
        final String hPassword = hostPassword;

        Authenticator authenticator = new Authenticator()
        {
            protected PasswordAuthentication getPasswordAuthentication()
            {
                return new PasswordAuthentication( hostUName, hPassword );
            }
        };

        // Get the default Session object.
        Session session = Session.getDefaultInstance( props, authenticator );

        try
        {
            // Create a default MimeMessage object.
            MimeMessage message = new MimeMessage( session );

            // Set From: header field of the header.
            message.setFrom( new InternetAddress( fromEmailId ) );

            // Set To: header field of the header.
            message.addRecipient( Message.RecipientType.TO, new InternetAddress( toEmailId ) );

            // Set Subject: header field
            message.setSubject( mailSubject );

            // Send the actual HTML message, as big as you like
            message.setContent( mailBody, "text/html" );

            // Send message
            Transport.send( message, message.getAllRecipients() );
            System.out.println( "Sent message successfully...." );
        }
        catch( Exception mex )
        {
            mex.printStackTrace();
        }

    }

    public static void main( String[] args )
    {

        String to = "someCorrectEmailID@xyz.com";
        String from = "someCorrectEmailID@xyz.com";
        String host = "correctHostForExch2010";
        String user = "correctUser";
        String password = "CorrectPassword";
        String subject = "Test Email";
        String body = "Hi there. This is a test email!";

        MailSender.sendHTMLEmail( from, to, host, user, password, subject, body );
    }
}

EDIT: I turned on debugging and it says

MAIL FROM:<someCorrectEmailID@xyz.com> 530 5.7.1 Client was not authenticated 
DEBUG SMTP: got response code 530, with response: 530 5.7.1 Client was not authenticated. 

Why would that be when the session authentication succeded?

  • 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-10T21:02:26+00:00Added an answer on June 10, 2026 at 9:02 pm

    Thanks Alex and Bill. I got it working by enabling the following property.

    props.put("mail.smtp.starttls.enable", "true");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a simple mail server using Python. I found smtpd that
I'm using Visual Studio 2010. I'm trying to write simple Camera class in OpenGL.
Trying to write a simple jQuery function that will multiple the index of an
I am trying to write code to send a simple mail from asp.net page.
I'm trying to write simple DAO that will create entity objects based on their
I'm trying to write a simple function in C that would calculate the difference
I'am trying to write simple script that will get files name from one folder
Im trying to write a simple program that will take 2 multi line inputs
I'm trying to write a behavior that will give my models access to a
Im trying to write a simple script that slides the next 'slide' div in

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.