Note that there are some explanatory texts on larger screens.

plurals
  1. POSending a mail to my gmail account from my computer in java
    text
    copied!<p>I am trying to send a mail to my gmail using the java code.</p> <p>This is my code:</p> <p>MailSender.java</p> <pre><code> package MailSenderInfo; import javax.mail.MessagingException; import javax.mail.internet.AddressException; public class MailSender { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub String from = "mymailId@enmediatech.com"; String to = "mymailIdto_send@gmail.com"; String subject = "Test"; String message = "A test message"; SendMailBody sendMail = new SendMailBody(from, to, subject, message); sendMail.send(); } </code></pre> <p>}</p> <p>SenderMailBody.java:</p> <pre><code>package MailSenderInfo; 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; import javax.mail.internet.MimeMessage.RecipientType; public class SendMailBody { private String from; private String to; private String subject; private String text; public SendMailBody(String from, String to, String subject, String text){ this.from = from; this.to = to; this.subject = subject; this.text = text; } public void send(){ Properties props = new Properties(); props.put("mail.smtp.host", "smtp.gmail.com"); props.put("mail.smtp.password", "pass"); props.put("mail.smtp.port", "587"); props.put("mail.smtp.auth", "true"); Session mailSession = Session.getDefaultInstance(props); Message simpleMessage = new MimeMessage(mailSession); InternetAddress fromAddress = null; InternetAddress toAddress = null; try { fromAddress = new InternetAddress(from); toAddress = new InternetAddress(to); } catch (AddressException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { simpleMessage.setFrom(fromAddress); simpleMessage.setRecipient(RecipientType.TO, toAddress); simpleMessage.setSubject(subject); simpleMessage.setText(text); Transport.send(simpleMessage); } catch (MessagingException e) { // TODO Auto-generated catch block e.printStackTrace(); } } </code></pre> <p>}</p> <p>This is the error which I am getting :</p> <pre><code> javax.mail.SendFailedException: Sending failed; nested exception is: class javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 25; nested exception is: java.net.ConnectException: Connection refused: connect at javax.mail.Transport.send0(Transport.java:218) at javax.mail.Transport.send(Transport.java:80) at MailSenderInfo.SendMailBody.send(SendMailBody.java:53) at MailSenderInfo.MailSender.main(MailSender.java:20) </code></pre> <p>Here in my system i have configured outlook and My system also have antivirus software.Whether Because of these two the above error can occur.Can anyone guide me.</p>
 

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