Java mail, set reply-to address not working

I wrote a small email sending program in java, it has from, to and reply-to address, when the client tries to reply to the mail, it should be able to reply to the reply-to address. Currently it's not working, my code is below:

// File Name

import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;

public class SendEmail
   public static void main(String [] args)

      // Recipient's email ID needs to be mentioned.
      String to = "";

      // Sender's email ID needs to be mentioned
      String from = "";

      // Assuming you are sending email from localhost
      String host = "localhost";

      // Get system properties
      Properties properties = System.getProperties();
    properties.put("mail.smtp.from", "");

      // Setup mail server
      properties.setProperty("", host);

      // Get the default Session object.
      Session session = Session.getDefaultInstance(properties);

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

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

         // Set To: header field of the header.
                                  new InternetAddress(to));

         // Set Subject: header field
         message.setSubject("This is the Subject Line!");

         // Now set the actual message
         message.setText("New Message goes here");

         // Send message
         System.out.println("Sent message successfully....");
      }catch (MessagingException mex) {

I used real gmail accounts. Can anyone help..?



Please note that:

  • "from" is not the same as "reply to"
  • according to the spec, the property for from-address is "mail.from"
  • the documentation for getDefaultInstance specifies that this only creates a new instance if there isn't an existing default instance and the properties are only used when creating a new instance. Further, the default instance is a global value and will be re-used, so unless you want the same "from"-address on all your email, you need to create new sessions (using getInstance())


MimeMessage message = new MimeMessage(session);
message.setReplyTo(new javax.mail.Address[]
    new javax.mail.internet.InternetAddress("")

Need Your Help

Twitter API - Logout

oauth twitter logout

I'm using OAuth in my web app, and users can login with twitter.

Can you get the column names from a SqlDataReader?

c# sqldatareader

After connecting to the database, can I get the name of all the columns that were returned in my SqlDataReader?