Reputation: 792
I am trying to send email through my outlook.com account (mapped to a specific domain, my email id would be like [email protected]
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
at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:2108) at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1609) at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1117) at org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:416) at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:306) at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:296) at com.sixthsense.lws.scheduler.TestMailSenderJob.sendMail(TestMailSenderJob.java:34) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at 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) at org.springframework.scheduling.support.MethodInvokingRunnable.run(MethodInvokingRunnable.java:65) at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:51) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:351) at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:178) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) at 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="[email protected]" />
<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("[email protected]");
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.
Upvotes: 2
Views: 7617
Reputation: 792
Fixed atlast, added from in message
message.setFrom("[email protected]");
Upvotes: 5
Reputation: 122
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.
Upvotes: 0