java - how to send mail using apache james email server to gmail -


i trying send mail using apache james server. have done james configuration.
code executes correctly there no exception. mail not deliver.
here sample code

public void sendmail(string tofield, string subject, users user,                                 httpservletrequest request)throws exception {     // todo auto-generated method stub     logger.info("sending mail....");     string loginlink = request.getscheme()  +"://" + request.getservername()       + ":" + request.getserverport() + request.getcontextpath()+"/auth/login";      // prepare evaluation context      final webcontext ctx = new webcontext(request, request.getsession()                                     .getservletcontext(),request.getlocale());      ctx.setvariable("eagletid", user.geteagletid());      ctx.setvariable("name", user.getfirstname());     ctx.setvariable("setsentdate", new date());      ctx.setvariable("password", user.getpassword());      ctx.setvariable("link",loginlink);      // create mail session       properties properties = new properties();       properties.put("mail.smtp.host", "localhost");       properties.put("mail.smtp.port", "25");       properties.put("mail.smtp.username", "coepleap");       properties.put("mail.smtp.password", "coepleap");       session session = session.getdefaultinstance(properties,new authenticator() {         protected passwordauthentication getpassauthentication(){             return new passwordauthentication("coepleap", "coepleap");         }     });      mimemessage message = new mimemessage(session);     mimemessagehelper helper = new mimemessagehelper(message, true, "utf-8");     message.setfrom(new internetaddress("coepleap"));     message.addrecipient(message.recipienttype.to, new internetaddress(tofield));     helper.setsubject(subject);      final string htmlcontent = this.templateengine.process("email.html",ctx);     helper.settext(htmlcontent,true);     transport.send(message);          }  } 

anyone can me out?

this code send mail using gmail

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 sendmail {  public static void main(string[] args) {      final string username = "username";     final string password = "fghdf";      properties props = new properties();     props.put("mail.smtp.auth", "true");     props.put("mail.smtp.starttls.enable", "true");     props.put("mail.smtp.host", "smtp.gmail.com");     props.put("mail.smtp.port", "587");      session session = session.getinstance(props,       new javax.mail.authenticator() {         protected passwordauthentication getpasswordauthentication() {             return new passwordauthentication(username, password);         }       });      try {          message message = new mimemessage(session);         message.setfrom(new internetaddress("from user"));         message.setrecipients(message.recipienttype.to,             internetaddress.parse("to user"));         message.setsubject("testing subject");         message.settext("dear user ,"             + "\n\n username xxx , pasword yyy");          transport.send(message);          system.out.println("done");      } catch (messagingexception e) {         throw new runtimeexception(e);     } } 

}


Comments

Popular posts from this blog

php - mySql Join with 4 tables -

css - Text drops down with smaller window -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -