Question mail program

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • 2147483648
    New Member
    • Feb 2014
    • 11

    Question mail program

    Code:
    package info.G2E;
    
    import java.util.Properties;
    
    import javax.mail.Address;
    import javax.mail.Message;
    import javax.mail.MessagingException;
    import javax.mail.Session;
    import javax.mail.Transport;
    import javax.mail.internet.InternetAddress;
    import javax.mail.internet.MimeMessage;
    
    public class SendEmail {
    	public static void main(String[] args) {
    		String to = "chalam.gd@gmail.com";
    		String from = "seshu.khs@gmail.com";
    		String host = "smtp.gmail.com";
    		// get the session object
    
    		Properties properties = System.getProperties();
    		properties.setProperty("mail.smtp.host", host);
    		properties.setProperty("mail.user", "chalam.gd@gmail.com");
    		properties.setProperty("mail.password", "tendulkar");
    		properties.setProperty("mail.port", "530");
    		properties.setProperty("mail.transport.protocol", "smtps");
    		properties.setProperty("mail.transport.protocol", "smtps");
    		properties.setProperty("mail.smtp.ssl.enable", "true");
    		properties.setProperty("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
    				
    		Session session = Session.getDefaultInstance(properties);
    
    		// compose the message
    
    		try {
    			MimeMessage message = new MimeMessage(session);
    			message.setFrom(new InternetAddress(from));
    			message.addRecipient(Message.RecipientType.TO,
    					new InternetAddress(to));
    			message.setSubject("ping");
    			message.setText("Welcome wonderful MailMessageSystem");
    
    			// send message
    			 	Transport.send(message);
    			System.out.print("message sent successfully..");
    
    		} catch (MessagingException mex) {
    			mex.printStackTrace();
    		}
    
    	}
    
    	@SuppressWarnings("unused")
    	private static MimeMessage newMimeMessage(Session session) {
    		// TODO Auto-generated method stub
    		return null;
    	}
    
    	@SuppressWarnings("unused")
    	private static Address newInternetAddress(String to) {
    		// TODO Auto-generated method stub
    		return null;
    	}
    
    }
    
    InConsole:
    javax.mail.MessagingException: Exception reading response;
      nested exception is:
    	javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
    	at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:1462)
    	at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1260)
    	at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:370)
    	at javax.mail.Service.connect(Service.java:275)
    	at javax.mail.Service.connect(Service.java:156)
    	at javax.mail.Service.connect(Service.java:105)
    	at javax.mail.Transport.send0(Transport.java:168)
    	at javax.mail.Transport.send(Transport.java:98)
    	at info.G2E.SendEmail.main(SendEmail.java:43)
    Caused by: javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
    	at sun.security.ssl.InputRecord.handleUnknownRecord(Unknown Source)
    	at sun.security.ssl.InputRecord.read(Unknown Source)
    	at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
    	at sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
    	at sun.security.ssl.SSLSocketImpl.readDataRecord(Unknown Source)
    	at sun.security.ssl.AppInputStream.read(Unknown Source)
    	at com.sun.mail.util.TraceInputStream.read(TraceInputStream.java:97)
    	at java.io.BufferedInputStream.fill(Unknown Source)
    	at java.io.BufferedInputStream.read(Unknown Source)
    	at com.sun.mail.util.LineInputStream.readLine(LineInputStream.java:75)
    	at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:1440)
    	... 8 more
    Last edited by Rabbit; Mar 11 '14, 04:17 PM. Reason: Please use [code] and [/code] tags when posting code or formatted data.
  • 2147483648
    New Member
    • Feb 2014
    • 11

    #2
    cud anybody help how to be get executed where is the problem here in this program?

    Comment

    • vitthaldevkar
      New Member
      • Aug 2012
      • 4

      #3
      Try this code for sending email on line no.43
      Code:
      Transport transport = session.getTransport("smtp");
      			transport.connect(host, Integer.parseInt(smtpPortStr), user, password);
      			transport.sendMessage(message, message.getAllRecipients());
      			transport.close();
      Last edited by Frinavale; Mar 19 '14, 04:02 PM. Reason: Added code tags and removed unnecessary punctuation

      Comment

      Working...