mdp
mdp

Reputation: 835

Not able to send emails to extrenal email addresses with Spring Java mail

I have developed a spring Java Mail application in my project.I have configured my company mail server name in Spring.xml file. I am using JavaMailSenderImpl.

My spring.xml

<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl"> 
 <property name="host" value="smtp.mycomp.com"/> 
</bean>

in my java class

public class ServiceEmail {

           public JavaMailSender getMailSender() {
            return mailSender;
        }

        @Autowired
        @Required
        public void setMailSender(JavaMailSender mailSender) {
            this.mailSender = mailSender;

             message.setTo("[email protected]");
         message.setFrom(fromEmailAddress);

             try{
                this.mailSender.send(preparator);
               }catch(MailException e){

                   e.printstacktrac();

}
}

}

But when I use this I am not able to send any mails to gmail or any other mail cllients it's failing with relaying denied exception. But it's working well with my internal server.Is it my mail server Issue or Do i need to configure for each and every email client.How can configure this to work all the mail clients.Can I configure in XML file?

Upvotes: 0

Views: 1451

Answers (1)

Bill Shannon
Bill Shannon

Reputation: 29971

This JavaMail FAQ entry should help.

Upvotes: 1

Related Questions