Good day,
I am self-taught with the help of a few free online courses in Java and very new to everything.
I'm struggling to run a code that's meant to send emails with a set content using my PC as localhost. using Netbeans IDE, I keep getting the following:
"Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - missing return statement
at SendEmail$Session.getDefaultInstance(SendEmail.java:29)
at SendEmail$Session.access$000(SendEmail.java:27)
at SendEmail.main(SendEmail.java:16)
C:\Users\ameer.hussein\AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:53: Java returned: 1
BUILD FAILED (total time: 1 second)"
I'm not sure what to do as I've tried multiple methods to overcome this issue and have a successful application. I've done what I know and can count on from my notes but still dont understand what this exception means.
the code im trying to run:
public class SendEmail {
public static void main(String [] args) {
String to = "example@email.com, example@email.com";
String from = "example@email.com";
String host = "localhost";
Properties properties = System.getProperties();
properties.setProperty("mail.smtp.host", host);
Session session = Session.getDefaultInstance(properties);
try
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
message.setSubject("This is the Subject Line!");
message.setText("This is actual message");
Transport.send(message);
System.out.println("Sent message successfully....");
}
}
void addRecipients(Message.RecipientType type, Address[] addresses)
throws MessagingException
Can someone please help me understand the exception and why it occurs?
Kind Regards, Ameer