import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
public class MailSender {
public static void main(String[] args) {
// TODO Auto-generated method stub
final String username = "xxx.xxxx@xxx.com";
final String password = "xxxo@xxxx";
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", "webmxzz.xxxxxxx.com");
props.put("mail.smtp.port", "587");
Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("xxxx.x@xxxx.com"));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse("xxxx.x@xxxx.com"));
message.setSubject("Testing Subject");
message.setText("Dear User,"
+ "\n\n No spam to my email, please!");
Transport.send(message);
System.out.println("Done");
} catch (MessagingException e) {
throw new RuntimeException(e);
}
}
}
While writing a code to send an email across the network i found this code.The jars i use are : javaee-api-5.jar
, activation.jar
and mail.jar
I compile the code and run it in eclipse.It works fine and sends a mail to the desired mail id but the problem occurs when i try to make a jar file out of it by exporting the jar file i get the warning : Jar exported .Finished with warnings.
The error i get is :
Could not find the main class: (class). Program will exit.
What could be the possible reason? Kindly help me find the solution.