Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Unable to send simple mail using java mail api  RSS feed

 
Jigar Naik
Ranch Hand
Posts: 762
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm trying to send mail using the java mail api but i am getting following exception

<blockquote>code:
<pre name="code" class="core">
javax.mail.SendFailedException: Sending failed;
nested exception is:
javax.mail.SendFailedException: Invalid Addresses;
nested exception is:
javax.mail.SendFailedException: 554 5.7.1 <jigarnaik@interactcrm.com>: Recipient address rejected: Access denied

at javax.mail.Transport.send0(Transport.java:219)
at javax.mail.Transport.send(Transport.java:81)
at org.icrm.sendmail.MailProcessor.sendMail(MailProcessor.java:34)
at org.icrm.sendmail.MailProcessor.main(MailProcessor.java:10)

</pre>
</blockquote>

my code for sending mail is as bellow

<blockquote>code:
<pre name="code" class="core">
//Get system properties
Properties props = System.getProperties();

//Setup mail server
props.put("mail.smtp.host",hostName);

//Get session
Session session = Session.getInstance(props);

//Define message
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
message.setSubject(subject);
message.setText(messageBody);

//Send message
Transport.send(message);
</pre>
</blockquote>
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It seems like your SMTP server does not allow your machine to send emails to jigarnaik@interactcrm.com. Contact your network admin to investigate.

I've had this problem as well at my work. I was only allowed to send emails to addresses in the same domain.
 
Jigar Naik
Ranch Hand
Posts: 762
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the reply,

but i am also trying to send mail on the same domain.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just about all mail servers need authentication these days - that's what "access denied" means. You need to pass along account name and password. See here for details.
 
Jigar Naik
Ranch Hand
Posts: 762
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks a lot,

After authentication it's working fine.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!