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
| import javax.mail.*;
import javax.mail.internet.*;
import java.util.Properties;
public class Emailer {
public Emailer()
{
}
private static Properties props = new Properties();
public static void SetMailConfig(String _transprotocol,String _hostname,String _username,String _passwd)
{
}
public void SendMail(String _To,String _Message,String _From,String _Subject) throws Exception
{
EmailParams mailparams=new EmailParams();
props.setProperty("mail.transport.protocol",mailparams.getProtocolType());
props.setProperty("mail.host", mailparams.getServerName());
props.setProperty("mail.user",mailparams.getLogin());
props.setProperty("mail.password", mailparams.getPassword());
Session mailSession = Session.getDefaultInstance(props, null);
mailSession.setDebug(true);
Transport transport = mailSession.getTransport();
MimeMessage message = new MimeMessage(mailSession);
message.setSubject(_Subject);
message.setFrom(new InternetAddress(_From));
message.setContent(_Message, "text/html");
message.addRecipient(Message.RecipientType.TO,
new InternetAddress(_To));
transport.connect();
transport.sendMessage(message,
message.getRecipients(Message.RecipientType.TO));
transport.close();
}
public static void main(String[] args) throws Exception {
Emailer _emailuser=new Emailer();
_emailuser.SendMail("DESTINATAIRE@SERVEUR.COM","COR DU MAIL","DELAPART@SERVEUR.COM"," SUJET");
}
} |
Partager