Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I am trying to send email through my outlook.com account (mapped to a specific domain, my email id would be like emailId@mydomain.com

I am getting the following exception.

2014-03-14 00:27:55,314 [pool-1-thread-1] ERROR org.springframework.scheduling.support.MethodInvokingRunnable - Invocation of method 'sendMail' on target class [class com.sixthsense.lws.scheduler.TestMailSenderJob] failed org.springframework.mail.MailSendException: Failed messages: com.sun.mail.smtp.SMTPSendFailedException: 501 5.5.4 Invalid Email address ; nested exception is: com.sun.mail.smtp.SMTPSenderFailedException: 501 5.5.4 Invalid Email address ; message exception details (1) are: Failed message 1: com.sun.mail.smtp.SMTPSendFailedException: 501 5.5.4 Invalid Email address ; nested exception is: com.sun.mail.smtp.SMTPSenderFailedException: 501 5.5.4 Invalid Email address

com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:2108) at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1609) com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1117) org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:416) org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:306) org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:296) com.sixthsense.lws.scheduler.TestMailSenderJob.sendMail(TestMailSenderJob.java:34) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at org.springframework.util.MethodInvoker.invoke(MethodInvoker.java:273) org.springframework.scheduling.support.MethodInvokingRunnable.run(MethodInvokingRunnable.java:65) org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:51) java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:351) at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:178) java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178) java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) at java.lang.Thread.run(Thread.java:722) Caused by: com.sun.mail.smtp.SMTPSenderFailedException: 501 5.5.4 Invalid Email address

at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1616) ... 20 more

My spring configuration are as below

<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
        <property name="host" value="smtp-mail.outlook.com" />
        <property name="port" value="587" />
         <property name="username" value="userid@mydomian.com" />
        <property name="password" value="password" />
        <property name="javaMailProperties">
            <props>
                <prop key="mail.smtp.auth">true</prop>
                <prop key="mail.smtp.starttls.enable">true</prop>
            </props>
        </property>
    </bean>

Following code sends the email

@Service
public class TestMailSenderJob {
    @Autowired
    JavaMailSender mailSender;
    public JavaMailSender getMailSender() {
        return mailSender;
    public void setMailSender(JavaMailSender mailSender) {
        this.mailSender = mailSender;
    @Scheduled(fixedDelay=5000)
    public void sendMail()
        System.out.println("############invoked sendMail");
        SimpleMailMessage message = new SimpleMailMessage();
        message.setTo("to@mailId.com");
        message.setSubject("Test mail "+new Date().toString());
        message.setText("test body");
        getMailSender().send(message);
        System.out.println("######### email send");

I am using oracle supplied jars for email version javamail-1.4.7 . Edit: I am able to send receive emails in my outlook account(used for smtp in the program) through outlook web interface.

Well, the server responded with 5.5.4 Invalid Email address which means that it doesn't accept to@mailId.com. Did you try any valid address? Is the mail from address correct? – Tasos P. Mar 13, 2014 at 19:26

I read in many places in the stacktrace this: "Invalid Email address". Please, check it in your code.

Another thing, for safety sake, please use the javax.mail-1.4.7 from maven repo.

It's already in Maven Central as well as the java.net maven repository. The maven coordinates are on the JavaMail java.net project page. – Bill Shannon Mar 15, 2014 at 21:46

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.