I found example:
package sendmailtest;
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
public class SendMailTest {
public static void main(String [] args) {
String to = "test@gmail.com";
String from = "myemail@gmail.com";
String host = "localhost";
Properties properties = System.getProperties();
properties.setProperty("smtp.gmail.com", 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("subject test");
message.setText("test msg");
Transport.send(message);
System.out.println("Sent message successfully....");
} catch (MessagingException mex) {
mex.printStackTrace();
}
}
}
I suppose I have to install my own email server as the example contains no password. Am I right? But is there API to send email via mailbox email server (eg gmail). Sorry for probably lame terms. Btw I need API that allow to insert images in a mail body.