• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Not able to send email via Domains default Email ID in java struts2

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am not able to send mail from my default email id of domain
Here is my code ( i have kept password blank ) :
package org.entity;

import com.opensymphony.xwork2.ActionSupport;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class ForgotAction extends ActionSupport
{
Forgot forgot;
public ForgotAction() {
// TODO Auto-generated constructor stub
}
public Forgot getForgot() {
return forgot;
}
public void setForgot(Forgot forgot) {
this.forgot = forgot;
}
@Override
public String execute() throws Exception {
String email,pass;
final String username = "info4blood@info4blood.in";
final String password = "";
Properties props = new Properties();
props.put("mail.smtp.auth","false");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", "mail.info4blood.in");
props.put("mail.smtp.port", "25");

Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
//System.out.println(session.getDebug());
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/info4blo_foryou", "info4blo_foryou", "siddheshkk");
System.out.println("Driver Loaded");
PreparedStatement ps = con
.prepareStatement("select email,password from bbinfo where code=?");
ps.setString(1, forgot.getCode());
ResultSet rs = ps.executeQuery();
if (rs.next()) {
email=rs.getString("email");
pass=rs.getString("password");
System.out.println("Here is your email id "+email+"and password is "+pass);
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(username));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(email));
message.setSubject("Password Retrieval");
message.setText("Dear user your password is "+ pass);
message.saveChanges();
Transport t=session.getTransport();
t.connect("mail.info4blood.in", username, password);
Transport.send(message);
System.out.println("Done");

} catch (MessagingException e) {
e.printStackTrace();
}
return "success";
} else {
return "error";
}
} catch (Exception e) {
e.printStackTrace();
}
return "success";
}
}

and below is my error :
javax.mail.AuthenticationFailedException
at javax.mail.Service.connect(Service.java:319)
at javax.mail.Service.connect(Service.java:169)
at javax.mail.Service.connect(Service.java:118)
at javax.mail.Transport.send0(Transport.java:188)
at javax.mail.Transport.send(Transport.java:118)
at org.entity.ForgotAction.execute(ForgotAction.java:68)
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:606)
at ognl.OgnlRuntime.invokeMethod(OgnlRuntime.java:891)
at ognl.OgnlRuntime.callAppropriateMethod(OgnlRuntime.java:1293)
at ognl.ObjectMethodAccessor.callMethod(ObjectMethodAccessor.java:68)
at com.opensymphony.xwork2.ognl.accessor.XWorkMethodAccessor.callMethodWithDebugInfo(XWorkMethodAccessor.java:117)
at com.opensymphony.xwork2.ognl.accessor.XWorkMethodAccessor.callMethod(XWorkMethodAccessor.java:108)
at ognl.OgnlRuntime.callMethod(OgnlRuntime.java:1369)
at ognl.ASTMethod.getValueBody(ASTMethod.java:90)
at ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:212)
at ognl.SimpleNode.getValue(SimpleNode.java:258)
at ognl.Ognl.getValue(Ognl.java:494)
at ognl.Ognl.getValue(Ognl.java:458)
at com.opensymphony.xwork2.ognl.OgnlUtil$2.execute(OgnlUtil.java:309)
at com.opensymphony.xwork2.ognl.OgnlUtil.compileAndExecute(OgnlUtil.java:340)
at com.opensymphony.xwork2.ognl.OgnlUtil.getValue(OgnlUtil.java:307)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:423)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:287)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:250)
at org.entity.CacheInterceptor.intercept(CacheInterceptor.java:26)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
at org.apache.struts2.interceptor.DeprecationInterceptor.intercept(DeprecationInterceptor.java:41)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:256)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)


Any help will be greatly appreciated
 
Ranch Hand
Posts: 417
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you have:
props.put("mail.smtp.auth","false");

and you get:
javax.mail.AuthenticationFailedException

so it looks like your smtp server requires authentication so you need to put:
props.put("mail.smtp.auth","true");

and that you need to provide proper authentication parameters.



 
siddhesh kalgaonkar
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried that but it doesnt work sir
 
A.J. Côté
Ranch Hand
Posts: 417
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

siddhesh kalgaonkar wrote:I tried that but it doesnt work sir



show me the lines where you provided proper authentication credentials.
 
siddhesh kalgaonkar
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes sure ,

final String username = "admin@info4blood.in";
final String password = "";
Properties props = new Properties();
props.put("mail.smtp.auth","true");
props.put("mail.smtp.starttls.enable", "false");
props.put("mail.smtp.host", "localhost");
props.put("mail.smtp.port", "25");
 
A.J. Côté
Ranch Hand
Posts: 417
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

siddhesh kalgaonkar wrote:Yes sure ,

final String username = "admin@info4blood.in";
final String password = "";
Properties props = new Properties();
props.put("mail.smtp.auth","true");
props.put("mail.smtp.starttls.enable", "false");
props.put("mail.smtp.host", "localhost");
props.put("mail.smtp.port", "25");



Do you know if your server requires authentication or not ???

With authentication password shouldn't be blank!

Try without authentication, props.put("mail.smtp.auth","false"); but then use:
t.connect("mail.info4blood.in");

When you use:
t.connect("mail.info4blood.in", username, password);

you would normally need to provide a valid passwd and use auth=true.

 
siddhesh kalgaonkar
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My problem is solved sir ,actually my project was not under ROOT folder in Cpanel thats y i was getting error . I had a contact with my providers customer support and they told me what was the actual problem. Thanks a lot sir for your continuous guidance
 
reply
    Bookmark Topic Watch Topic
  • New Topic