MailSenderSessionBean.java
Dosyayı İndir
package com.todo.ejb;
import java.util.Properties;
import javax.ejb.Stateless;
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;
@Stateless
public class MailSenderSessionBean implements MailSenderSessionBeanLocal {
public void sendMail(String to,String from,String subject,String body)
throws MessagingException{
Properties props = System.getProperties();
props.put("mail.smtp.host", "mail@godoro.com");
props.put("mail.smtp.auth", "true");
// Session session = Session.getDefaultInstance(props, null);
Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(
"membership@godoro.com", "xxxxxxx");
}
});
Message msg = new MimeMessage(session);
InternetAddress addressTo = new InternetAddress(to);
msg.setRecipient(Message.RecipientType.TO, addressTo);
InternetAddress addressFrom = new InternetAddress(from);
msg.setFrom(addressFrom);
msg.setSubject(subject);
msg.setContent(body, "text/html; charset=UTF-8");
Transport.send(msg);
}
}
Dosyayı İndir