1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
| package classes;
import java.util.Properties;
import javax.mail.Authenticator;
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 MailClass extends SuperClass {
Session sess = null;
private String destinat = "";
private String subject = "";
private String content = "";
public MailClass() {
super();
Properties properties = new Properties();
properties.put("mail.smtp.auth", "true");
properties.put("mail.smtp.host", Datas.SMTPHOST);
properties.put("mail.smtp.port", Datas.SMTPPORT);
properties.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
sess = Session.getInstance(properties, new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(Datas.USERMAIL, Datas.PWDMAIL);
}
});
}
public void sendMessage() throws MessagingException {
Message message = new MimeMessage(sess);
message.setFrom(new InternetAddress(Datas.FROMMAIL));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(destinat));
message.setSubject(subject);
message.setContent(content, "text/html; charset=UTF-8");
message.setHeader("Content-Type", "text/html; charset=\"UTF-8\"");
Transport.send(message);
}
/**
* @param destinat the destinat to set
*/
public void setDestinat(String destinat) {
this.destinat = destinat;
}
/**
* @param subject the subject to set
*/
public void setSubject(String subject) {
this.subject = subject;
}
/**
* @param content the content to set
*/
public void setContent(String content) {
this.content = content;
}
} |
Partager