Note that there are some explanatory texts on larger screens.

plurals
  1. POSending a mail through a java program in detail
    text
    copied!<p>I am not able to send an email i think there may be some issue can u please check the code</p> <pre><code>*import java.util.Date; import java.util.Properties; import javax.mail.Address; import javax.mail.MessagingException; import javax.mail.PasswordAuthentication; import javax.mail.Session; import javax.mail.Transport; import javax.mail.internet.AddressException; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; public class Mail { public static void sendReminder(String Message) throws AddressException, MessagingException{ String to="jackson123@gmail.com"; String password="784518"; String from = "michal@gmail.com"; String subject = "Reminder"; String body = "Dear Sir"; Properties props = new Properties(System.getProperties()); // -- Attaching to default Session, or we could start a new one -- props.put("mail.smtp.host", "smtp.gmail.com"); SMTPAuthenticator smtpAuth = null; Session session = Session.getDefaultInstance(props, smtpAuth); // -- Create a new message -- javax.mail.Message msg = new MimeMessage(session); // -- Set the FROM and TO fields -- try { msg.setFrom(new InternetAddress(from)); msg.setRecipients(javax.mail.Message.RecipientType.TO, InternetAddress.parse(username, false)); msg.setSubject(subject); msg.setContent(body, "text/html"); // -- Set some other header information -- msg.setSentDate(new Date()); // -- Send the message -- Transport.send(msg); //MessageDao.addToHistory(task, new Date(), remindBefore); }catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } private static class SMTPAuthenticator extends javax.mail.Authenticator { private PasswordAuthentication authentication; public SMTPAuthenticator(String username,String password) { authentication = new PasswordAuthentication(username, password); } protected PasswordAuthentication getPasswordAuthentication() { return authentication; } } public static void main(String args[]) throws AddressException, MessagingException { Mail m=new Mail(); Mail.sendReminder("this is a test mail"); } }* com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Must issue a STARTTLS command first. 7sm50596735paf.22 - gsmtp at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1388) at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:959) </code></pre> <p>the following is the error after executing this program... i think some problem is there in the there if it is possible please check it </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