• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Sending Email using Java gives error message

 
vinoth Robert
Ranch Hand
Posts: 31
Firefox Browser MS IE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Shanky Sohar
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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");
 
vinoth Robert
Ranch Hand
Posts: 31
Firefox Browser MS IE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20613
63
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Shanky Sohar
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Shanky Sohar
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 31
Firefox Browser MS IE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
just write IP address instead of host name nothing else..
 
vinoth Robert
Ranch Hand
Posts: 31
Firefox Browser MS IE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20613
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vinoth Robert, hasn't anyone told you you should UseCodeTags instead of colouring? If not, then now someone has
 
Shanky Sohar
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 31
Firefox Browser MS IE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Shanky Sohar.
 
Shanky Sohar
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
vinoth Robert wrote:thanks Shanky Sohar.


Most welcome
 
Clay Ferguson
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic