aspose file tools*
The moose likes Other JSE/JEE APIs and the fly likes Sending Email using Java gives error message Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Sending Email using Java gives error message" Watch "Sending Email using Java gives error message" New topic
Author

Sending Email using Java gives error message

vinoth Robert
Ranch Hand

Joined: Feb 02, 2011
Posts: 31

Hi,
I am using java application to send email.
My Email server is "Godaddy.com".
host is smtpout.secureserver.net
port is : 25
when I use gmail(smtp.gmail.com) it works fine, but using godaddy I can't send mail
this is my code:


-----------------------------------------------------------------------

Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
Properties props = new Properties();
props.setProperty("mail.transport.protocol", "smtp");
props.setProperty("mail.host", "relay-hosting.secureserver.net");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "25");
props.put("mail.smtp.socketFactory.port", "25");
//props.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.socketFactory.fallback", "false");
props.setProperty("mail.smtp.quitwait", "false");

Session session = Session.getDefaultInstance(props,
new javax.mail.Authenticator()
{
protected PasswordAuthentication getPasswordAuthentication()
{ return new PasswordAuthentication("username@xx.com","pass"); }
});

MimeMessage message = new MimeMessage(session);
message.setSender(new InternetAddress("vinoth@clss.in"));
message.setSubject("test");
message.setContent("Hi pon", "text/html");
message.setRecipient(Message.RecipientType.TO, new InternetAddress("xxxx@clss.in"));
Transport.send(message);

---------------------------------------------------------------------------------------------------------------------------------------------------------

I get Error message like this:
--------------------------------------

javax.mail.SendFailedException: Invalid Addresses;
nested exception is:
com.sun.mail.smtp.SMTPAddressFailedException: 553 sorry, relaying denied from your location [115.117.232.45] (#5.7.1)

at com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1835)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1098)
at javax.mail.Transport.send0(Transport.java:195)
at javax.mail.Transport.send(Transport.java:124)
at Mailing.SendMail.clss_sendMail(SendMail.java:107)
at Mailing.SendMail.main(SendMail.java:31)
Caused by: com.sun.mail.smtp.SMTPAddressFailedException: 553 sorry, relaying denied from your location [115.117.232.45] (#5.7.1)

at com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1686)
... 5 more



any idea please?


vinoth.R
Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051

Even i have faced this error invalid address error was coming because of from addres
so make sure that from adress field will be same,as what you have authenticated..


and before saying
transport.send(message);

First get the transport protocol using...
Transport transport = session.getTransport("smtp");

SCJP6.0,My blog Ranchers from Delhi
vinoth Robert
Ranch Hand

Joined: Feb 02, 2011
Posts: 31

hi Shanky Sohar,

i checked that sender and the authentication email ids are same.
and i have added this line

Transport transport = session.getTransport("smtp");

still i get the same error.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19719
    
  20

See that error message, "553 sorry, relaying denied from your location"? That means that you're connecting perfectly. The problem is after that - you are trying to relay, and that's not allowed with this SMTP server. The problem is not in your code but in the server configuration.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051

Why not you try using IP Address,Instead of host name.I hope it will work fine.

Otherwise raise a ticket request on godaddy.com..about the issue as you may not be having a server access..
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42276
    
  64
Why not you try using IP Address,Instead of host name.I hope it will work fine.

Why would it? As Rob pointed out, connectivity is not the problem.


Ping & DNS - my free Android networking tools app
Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051

Ulf Dittmer wrote:
Why not you try using IP Address,Instead of host name.I hope it will work fine.

Why would it? As Rob pointed out, connectivity is not the problem.


Yes you are right..Connectivity is working fine..but here is the solution.
"The email program you already use for sending and receiving messages can easily be used along with the server just by using the IP address "127.0.0.1" instead of your current SMTP host"

source is
http://www.softheap.com/smtprelay.html

just giving a try to solve it..May be it works with a IP.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42276
    
  64
You fundamentally misunderstand what the page you linked to is talking about; it's about running a local mail server - that's hardly the sort of solution vinoth Robert is looking for.
vinoth Robert
Ranch Hand

Joined: Feb 02, 2011
Posts: 31

hi friends,

how to set ip address instead of host name?

OR

can any one give me the code which works correctly in Godaddy server(relay-hosting.secureserver.net)?
Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051

just write IP address instead of host name nothing else..
vinoth Robert
Ranch Hand

Joined: Feb 02, 2011
Posts: 31

Finally I got it.

the Code is

public void sendMail() throws Exception
{
try
{
Properties props = System.getProperties();
props.setProperty("mail.transport.protocol", "smtp");
props.setProperty("mail.host", "relay-hosting.secureserver.net");

props.put("mail.smtp.auth", "true");
props.setProperty("mail.user", "xxxxxx@xxxx.com");
props.setProperty("mail.password", "password");

Session mailSession = Session.getDefaultInstance(props, null);
mailSession.setDebug(true);
Transport transport = mailSession.getTransport("smtp");
MimeMessage message = new MimeMessage(mailSession);
message.setSentDate(new java.util.Date());
message.setSubject("Hi Test");
message.setFrom(new InternetAddress("xxxxx@xxxx.com"));
message.setRecipient(Message.RecipientType.TO, new InternetAddress("toxxx@xxxx.com"));
MimeMultipart multipart = new MimeMultipart("related");
// first part (the html)
BodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setContent("Hi rsgdsdgdfgsdfg", "text/html");

// add it
multipart.addBodyPart(messageBodyPart);
// put everything together
message.setContent(multipart);

transport.connect("relay-hosting.secureserver.net", "xxxxxxx@xxx.com","password");
transport.sendMessage(message, message.getRecipients(Message.RecipientType.TO));
transport.close();

}
catch (Exception e) {
e.printStackTrace();
}
}
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19719
    
  20

Vinoth Robert, hasn't anyone told you you should UseCodeTags instead of colouring? If not, then now someone has
Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051

Remember using getDefaultInstance will create a shared session that can be used by other application too.


So its better to use a connection dedicated to your application.Use

vinoth Robert
Ranch Hand

Joined: Feb 02, 2011
Posts: 31

thanks Shanky Sohar.
Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051

vinoth Robert wrote:thanks Shanky Sohar.


Most welcome
Clay Ferguson
Greenhorn

Joined: Aug 26, 2011
Posts: 1
Thanks Vinoth:

This is what worked for me (code below). I needed port 80, which was the main trick:

(the email I sent DID come into my spam account on google, but still, that was a successful send)

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Sending Email using Java gives error message