473,466 Members | 1,347 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Question mail program

2147483648
11 New Member
Expand|Select|Wrap|Line Numbers
  1. package info.G2E;
  2.  
  3. import java.util.Properties;
  4.  
  5. import javax.mail.Address;
  6. import javax.mail.Message;
  7. import javax.mail.MessagingException;
  8. import javax.mail.Session;
  9. import javax.mail.Transport;
  10. import javax.mail.internet.InternetAddress;
  11. import javax.mail.internet.MimeMessage;
  12.  
  13. public class SendEmail {
  14.     public static void main(String[] args) {
  15.         String to = "chalam.gd@gmail.com";
  16.         String from = "seshu.khs@gmail.com";
  17.         String host = "smtp.gmail.com";
  18.         // get the session object
  19.  
  20.         Properties properties = System.getProperties();
  21.         properties.setProperty("mail.smtp.host", host);
  22.         properties.setProperty("mail.user", "chalam.gd@gmail.com");
  23.         properties.setProperty("mail.password", "tendulkar");
  24.         properties.setProperty("mail.port", "530");
  25.         properties.setProperty("mail.transport.protocol", "smtps");
  26.         properties.setProperty("mail.transport.protocol", "smtps");
  27.         properties.setProperty("mail.smtp.ssl.enable", "true");
  28.         properties.setProperty("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
  29.  
  30.         Session session = Session.getDefaultInstance(properties);
  31.  
  32.         // compose the message
  33.  
  34.         try {
  35.             MimeMessage message = new MimeMessage(session);
  36.             message.setFrom(new InternetAddress(from));
  37.             message.addRecipient(Message.RecipientType.TO,
  38.                     new InternetAddress(to));
  39.             message.setSubject("ping");
  40.             message.setText("Welcome wonderful MailMessageSystem");
  41.  
  42.             // send message
  43.                  Transport.send(message);
  44.             System.out.print("message sent successfully..");
  45.  
  46.         } catch (MessagingException mex) {
  47.             mex.printStackTrace();
  48.         }
  49.  
  50.     }
  51.  
  52.     @SuppressWarnings("unused")
  53.     private static MimeMessage newMimeMessage(Session session) {
  54.         // TODO Auto-generated method stub
  55.         return null;
  56.     }
  57.  
  58.     @SuppressWarnings("unused")
  59.     private static Address newInternetAddress(String to) {
  60.         // TODO Auto-generated method stub
  61.         return null;
  62.     }
  63.  
  64. }
  65.  
  66. InConsole:
  67. javax.mail.MessagingException: Exception reading response;
  68.   nested exception is:
  69.     javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
  70.     at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:1462)
  71.     at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1260)
  72.     at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:370)
  73.     at javax.mail.Service.connect(Service.java:275)
  74.     at javax.mail.Service.connect(Service.java:156)
  75.     at javax.mail.Service.connect(Service.java:105)
  76.     at javax.mail.Transport.send0(Transport.java:168)
  77.     at javax.mail.Transport.send(Transport.java:98)
  78.     at info.G2E.SendEmail.main(SendEmail.java:43)
  79. Caused by: javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
  80.     at sun.security.ssl.InputRecord.handleUnknownRecord(Unknown Source)
  81.     at sun.security.ssl.InputRecord.read(Unknown Source)
  82.     at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
  83.     at sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
  84.     at sun.security.ssl.SSLSocketImpl.readDataRecord(Unknown Source)
  85.     at sun.security.ssl.AppInputStream.read(Unknown Source)
  86.     at com.sun.mail.util.TraceInputStream.read(TraceInputStream.java:97)
  87.     at java.io.BufferedInputStream.fill(Unknown Source)
  88.     at java.io.BufferedInputStream.read(Unknown Source)
  89.     at com.sun.mail.util.LineInputStream.readLine(LineInputStream.java:75)
  90.     at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:1440)
  91.     ... 8 more
Mar 11 '14 #1
2 1665
2147483648
11 New Member
cud anybody help how to be get executed where is the problem here in this program?
Mar 11 '14 #2
vitthaldevkar
4 New Member
Try this code for sending email on line no.43
Expand|Select|Wrap|Line Numbers
  1. Transport transport = session.getTransport("smtp");
  2.             transport.connect(host, Integer.parseInt(smtpPortStr), user, password);
  3.             transport.sendMessage(message, message.getAllRecipients());
  4.             transport.close();
Mar 18 '14 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

21
by: tyler_durden | last post by:
hi there peeps... like I say in the topic, I need to do an e-mail program in C language, and has to be made until the 3th of january..the problem is I'm having some problems with it. I was...
0
by: Chuck | last post by:
Just needed to confirm my new mail client is working.
2
by: cj | last post by:
Say I could say for a fact the program would work only with Outlook. Does outlook make any methods or properties available that would allow me to launch it and populate subject and body? How...
1
dmjpro
by: dmjpro | last post by:
i am newbei in java mail program .... recently i came to know that without SMTP specification of a server i can't run the java mail program succcfully ..... is that true ..... if possible plz...
1
by: vinodkus | last post by:
Problem 1I m writing a mail program in asp my first page is mail.asp where I subitting address, subject, body and second page is send_mail.asp Contents of Page mail.asp <html> <head> <meta...
3
by: Mufasa | last post by:
Does anybody have any code that would go out to an e-mail account (I'm using g-mail), get the e-mails and if there are any attachments, get those and save them on the local hard drive? I don't...
6
by: Jack Russell | last post by:
I have the following code Public Sub StartDefaultMail( _ ByVal As String, _ Optional ByVal Subject As String = "", _ Optional ByVal Message As String = "" _ ) 'To use this code you need to...
0
by: Markleszczynski | last post by:
I don't even know where to start on this one. I am trying to write code that will bring up a new pre-addressed e-mail message and fill the body with selected text. I am new to visual basic and that...
6
by: egaskill | last post by:
So I'm trying to figure out something...we need our company's internal PHP based intranet site redone as it runs horribly. We recently hired a company to come in and take a look at the code and...
3
by: Microsoft | last post by:
Hi I have a c# program that continually runs 24/7 and performs a variety of tasks based on a timer. There is one routine that hangs every Saturday morning without fail. If I restart the...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.