java - Sending two different emails at the same time using JavaMail API -


i'm using javamail api notify administrator when there's data insertion in database

this works fine. admin receives notification of data entry.

however, need notify client sending him confirmation @ same time, not work. customer not receive confirmation. want paste confirmation number in subject. related port conflict?

emailadmin.sendemail(to, subject, body); emailcustomer.sendemail(em, subjectsub, bodybod, cn); 

emailadmin.java

    package session;  import java.util.date; import java.util.properties; import javax.ejb.localbean; import javax.ejb.stateless; import javax.mail.*; import javax.mail.internet.internetaddress; import javax.mail.internet.mimemessage;  @stateless @localbean public class emailadmin {      private final int port = 465;     private final string host = "smtp.server.com";     private final string = "admin@domain.com";     private final boolean auth = true;     private final string username = "admin@domain.com";     private final string password = "password";     private final protocol protocol = protocol.smtps;     private final boolean debug = true;      public void sendemail(string to, string subject, string body) {          properties props = new properties();         props.put("mail.smtp.host", host);         props.put("mail.smtp.port", port);          switch (protocol) {             case smtps:                 props.put("mail.smtp.ssl.enable", true);                 break;             case tls:                 props.put("mail.smtp.starttls.enable", true);                 break;         }          authenticator authenticator = null;         if (auth) {             props.put("mail.smtp.auth", true);             authenticator = new authenticator() {                 private final passwordauthentication pa = new passwordauthentication(username, password);                 @override                 public passwordauthentication getpasswordauthentication() {                     return pa;                 }             };         }          session session = session.getinstance(props, authenticator);         session.setdebug(debug);          mimemessage message = new mimemessage(session);         try {             message.setfrom(new internetaddress(from));             internetaddress[] address = {new internetaddress(to)};             message.setrecipients(message.recipienttype.to, address);             message.setsubject(subject);             message.setsentdate(new date());             message.settext(body);              transport.send(message);         } catch (messagingexception ex) {         }     } } 

emailcustomer.java

    package session;  import java.util.date; import java.util.properties; import javax.ejb.localbean; import javax.ejb.stateless; import javax.mail.*; import javax.mail.internet.internetaddress; import javax.mail.internet.mimemessage;  @stateless @localbean public class emailcustomer {      private final int port = 465;     private final string host = "smtp.server.com";     private final string = "admin@domain.com";     private final boolean auth = true;     private final string username = "admin@domain.com";     private final string password = "password";     private final protocol protocol = protocol.smtps;     private final boolean debug = true;      public void sendemail(string em, string subjectsub, string bodybod, string cn) {          properties props = new properties();         props.put("mail.smtp.host", host);         props.put("mail.smtp.port", port);          switch (protocol) {             case smtps:                 props.put("mail.smtp.ssl.enable", true);                 break;             case tls:                 props.put("mail.smtp.starttls.enable", true);                 break;         }          authenticator authenticator = null;         if (auth) {             props.put("mail.smtp.auth", true);             authenticator = new authenticator() {                 private final passwordauthentication pa = new passwordauthentication(username, password);                 @override                 public passwordauthentication getpasswordauthentication() {                     return pa;                 }             };         }          session session = session.getinstance(props, authenticator);         session.setdebug(debug);          mimemessage message = new mimemessage(session);         try {             message.setfrom(new internetaddress(from));             internetaddress[] address = {new internetaddress(em)};             message.setrecipients(message.recipienttype.to, address);             message.setsubject(subject, cn);             message.setsentdate(new date());             message.settext(body);              transport.send(message);         } catch (messagingexception ex) {         }     } } 


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -