Note that there are some explanatory texts on larger screens.

plurals
  1. POSendgrid send mail error using java
    text
    copied!<pre><code>public class SimpleMail { private static final String SMTP_HOST_NAME = "smtp.sendgrid.net"; private static final String SMTP_AUTH_USER = "Myusername"; private static final String SMTP_AUTH_PWD = "Password"; public static void main(String[] args) throws Exception{ new SimpleMail().test(); } public void test() throws Exception{ Properties props = new Properties(); props.put("mail.transport.protocol", "smtp"); props.put("mail.smtp.host", SMTP_HOST_NAME); props.put("mail.smtp.port", "465"); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.socketFactory.port", "465"); Authenticator auth = new SMTPAuthenticator(); Session mailSession = Session.getDefaultInstance(props, auth); // uncomment for debugging infos to stdout mailSession.setDebug(true); Transport transport = mailSession.getTransport(); MimeMessage message = new MimeMessage(mailSession); Multipart multipart = new MimeMultipart("alternative"); BodyPart part1 = new MimeBodyPart(); part1.setText("This is multipart mail and u read part1......"); BodyPart part2 = new MimeBodyPart(); part2.setContent("&lt;b&gt;This is multipart mail and u read part2......&lt;/b&gt;","text.html"); multipart.addBodyPart(part1); multipart.addBodyPart(part2); message.setContent(multipart); message.setFrom(new InternetAddress("aKrishiv@absinessware.com")); message.setSubject("This is the subject"); message.addRecipient(Message.RecipientType.TO,new InternetAddress("someone@somewhere.com")); transport.connect(); transport.sendMessage(message,message.getRecipients(Message.RecipientType.TO)); transport.close();` </code></pre> <p>Can some one help me i am trying to send mail using SMTP the above code is found <a href="http://sendgrid.com/docs/Code_Example" rel="nofollow">here</a></p> <p>While running the code on eclipse i got this error</p> <pre><code>DEBUG: setDebug: JavaMail version 1.5.0 DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle] DEBUG SMTP: useEhlo true, useAuth true Username: Myusername Password: Mypassword DEBUG SMTP: useEhlo true, useAuth true DEBUG SMTP: trying to connect to host "smtp.sendgrid.net", port 587, isSSL false Exception in thread "main" com.sun.mail.util.MailConnectException: Couldn't connect to host, port: smtp.sendgrid.net, 587; timeout -1; nested exception is: java.net.ConnectException: Connection timed out: connect at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1961) at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:654) at javax.mail.Service.connect(Service.java:367) at javax.mail.Service.connect(Service.java:226) at javax.mail.Service.connect(Service.java:175) at SimpleMail.test(SimpleMail.java:53) at SimpleMail.main(SimpleMail.java:14) Caused by: java.net.ConnectException: Connection timed out: connect at java.net.DualStackPlainSocketImpl.connect0(Native Method) at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source) at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source) at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source) at java.net.AbstractPlainSocketImpl.connect(Unknown Source) at java.net.PlainSocketImpl.connect(Unknown Source) at java.net.SocksSocketImpl.connect(Unknown Source) at java.net.Socket.connect(Unknown Source) at java.net.Socket.connect(Unknown Source) at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:297) at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:229) at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1927) ... 6 more # </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload