fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. // Recipient's email ID needs to be mentioned.
  13. String to = "abcd@gmail.com";
  14.  
  15. // Sender's email ID needs to be mentioned
  16. String from = "web@gmail.com";
  17.  
  18. // Assuming you are sending email from localhost
  19. String host = "localhost";
  20.  
  21. // Get system properties
  22. Properties properties = System.getProperties();
  23.  
  24. // Setup mail server
  25. properties.setProperty("mail.smtp.host", host);
  26.  
  27. // Get the default Session object.
  28. Session session = Session.getDefaultInstance(properties);
  29.  
  30. try{
  31. // Create a default MimeMessage object.
  32. MimeMessage message = new MimeMessage(session);
  33.  
  34. // Set From: header field of the header.
  35. message.setFrom(new InternetAddress(from));
  36.  
  37. // Set To: header field of the header.
  38. message.addRecipient(Message.RecipientType.TO,
  39. new InternetAddress(to));
  40.  
  41. // Set Subject: header field
  42. message.setSubject("This is the Subject Line!");
  43.  
  44. // Now set the actual message
  45. message.setText("This is actual message");
  46.  
  47. // Send message
  48. Transport.send(message);
  49. System.out.println("Sent message successfully....");
  50. }catch (MessagingException mex) {
  51. mex.printStackTrace();
  52. }
  53. }
  54. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:28: error: cannot find symbol
      Session session = Session.getDefaultInstance(properties);
      ^
  symbol:   class Session
  location: class Ideone
Main.java:28: error: cannot find symbol
      Session session = Session.getDefaultInstance(properties);
                        ^
  symbol:   variable Session
  location: class Ideone
Main.java:32: error: cannot find symbol
         MimeMessage message = new MimeMessage(session);
         ^
  symbol:   class MimeMessage
  location: class Ideone
Main.java:32: error: cannot find symbol
         MimeMessage message = new MimeMessage(session);
                                   ^
  symbol:   class MimeMessage
  location: class Ideone
Main.java:35: error: cannot find symbol
         message.setFrom(new InternetAddress(from));
                             ^
  symbol:   class InternetAddress
  location: class Ideone
Main.java:38: error: package Message does not exist
         message.addRecipient(Message.RecipientType.TO,
                                     ^
Main.java:39: error: cannot find symbol
                                  new InternetAddress(to));
                                      ^
  symbol:   class InternetAddress
  location: class Ideone
Main.java:48: error: cannot find symbol
         Transport.send(message);
         ^
  symbol:   variable Transport
  location: class Ideone
Main.java:50: error: cannot find symbol
      }catch (MessagingException mex) {
              ^
  symbol:   class MessagingException
  location: class Ideone
9 errors
stdout
Standard output is empty