outlook - Using Java Mail -


i send email using java application. when press button, there should automatically sent email , somehow didn't find solution yet. found lot of example codes in internet, doesn't matter if use gmail / gmx or outlook, receive message :

"could not connect smtp host: mail.gmx.net, port: 587; nested exception is: java.net.connectexception: connection timed out: connect"

based on domain, host mail.gmx.net or smtp.office365.com etc.. think there's somehow connection problem, wasn't able fix it. have ideas / codes worked ?

thank in advance.

tobias

use code send email .this works fine me

package sendmail;  import java.util.properties; import javax.mail.message; import javax.mail.messagingexception; import javax.mail.session; import javax.mail.transport; import javax.mail.internet.addressexception; import javax.mail.internet.internetaddress; import javax.mail.internet.mimemessage;  /**  * @author akash073  *  */  public class crunchifyjavamailexample {      //static properties mailserverproperties;    // static session getmailsession;   //  static mimemessage generatemailmessage;      public static void main(string args[]) throws addressexception, messagingexception {         generateandsendemail();         system.out.println("\n\n ===> java program has sent email successfully. check email..");     }      public static void generateandsendemail() throws addressexception, messagingexception {          string smtphost="put host";         string smtpuser="username in full @somthing.com";         string smtppassword="your password";         int smtpport=25;//port may vary.check yours smtp port         // step1         system.out.println("\n 1st ===> setup mail server properties..");         properties mailserverproperties = system.getproperties();         //mailserverproperties.put("mail.smtp.ssl.trust", smtphost); //        mailserverproperties.put("mail.smtp.starttls.enable", true); // added line         mailserverproperties.put("mail.smtp.host", smtphost);         mailserverproperties.put("mail.smtp.user", smtpuser);         mailserverproperties.put("mail.smtp.password", smtppassword);         mailserverproperties.put("mail.smtp.port", smtpport);          mailserverproperties.put("mail.smtp.starttls.enable", "true");         system.out.println("mail server properties have been setup successfully..");          // step2         system.out.println("\n\n 2nd ===> mail session..");         session getmailsession = session.getdefaultinstance(mailserverproperties, null);         mimemessage generatemailmessage = new mimemessage(getmailsession);         generatemailmessage.setfrom (new internetaddress (smtpuser));         generatemailmessage.addrecipient(message.recipienttype.to, new internetaddress("akash073@waltonbd.com"));         generatemailmessage.addrecipient(message.recipienttype.cc, new internetaddress("akash073@gmail.com"));         generatemailmessage.setsubject("greetings crunchify..");         string emailbody = "2.test email crunchify.com javamail api example. " + "<br><br> regards, <br>crunchify admin";         generatemailmessage.setcontent(emailbody, "text/html");         system.out.println("mail session has been created successfully..");          // step3         system.out.println("\n\n 3rd ===> session , send mail");         transport transport = getmailsession.gettransport("smtp");          // enter correct gmail userid , password         // if have 2fa enabled provide app specific password         transport.connect(smtphost,smtpport, smtpuser, smtppassword);         transport.sendmessage(generatemailmessage, generatemailmessage.getallrecipients());         transport.close();     } } 

for more info crunchify


Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -