Good day!
I give my thanks to you.
Everything worked fine.
I have another question.
The code whick worked is this
import javax.mail.*;
import javax.mail.internet.*;
public class simplemail {
public static void send(
String smtpHost, int smtpPort,
String from, String to,
String subject, String content) {
try{
java.util.Properties props = new java.util.Properties();
props.put("mail.smtp.host", smtpHost);
props.put("mail.smtp.port", ""+smtpPort);
Session session = Session.getDefaultInstance(props, null);
//Store store = session.getStore();
//Folder folder = store.getFolder("INBOX");
//System.out.println(folder.getMessage(1));
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(from));
msg.setRecipient(Message.RecipientType.TO, new InternetAddress(to));
msg.setSubject(subject);
msg.setText(content);
Transport.send(msg);
}catch(Exception e){e.printStackTrace();}
}
public static void main(String[] args) throws Exception {
send("myhostname", 25, "Fedai@bankrespublika.az", "fedai@bankrespublika.az",
"Driving away", "I'm firing you");
}
}
When I uncomment the commented part it throws the exception
javax.mail.NoSuchProviderException: Invalid protocol: null
at javax.mail.Session.getProvider(Session.java:265)
at javax.mail.Session.getStore(Session.java:363)
at javax.mail.Session.getStore(Session.java:343)
at javax.mail.Session.getStore(Session.java:329)
at simplemail.send(simplemail.java:17)
at simplemail.main(simplemail.java:35)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:78)
Where in this code do I have to configure protocol?
Thank you!