Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted by Przemyslaw Kadej ( 18 years ago )
package korporacja;
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class WyslijKod extends HttpServlet {
private RequestDispatcher disp;
// dane wysylajacego
private String SMTP_HOST_NAME;
private String SMTP_AUTH_USER;
private String SMTP_AUTH_PWD;
private static final String temat = "Kod Aktywujacy korporacja.com";
private String FROM;
private Session sesja;
public void init(ServletConfig config) throws ServletException {
super.init(config);
SMTP_AUTH_PWD = config.getInitParameter("PASSWORD");
FROM = config.getInitParameter("MAIL");
SMTP_AUTH_USER = config.getInitParameter("SMTP_AUTH_USER");
SMTP_HOST_NAME = config.getInitParameter("SMTP_HOST_NAME");
Properties pro = new Properties();
pro.put("mail.smtp.host", SMTP_HOST_NAME);
pro.put("mail.smtp.auth", "true");
Authenticator auth = new SMTPAuthenticator();
sesja = Session.getDefaultInstance(pro, auth);
sesja.setDebug(false);
}
private class SMTPAuthenticator extends javax.mail.Authenticator {
public PasswordAuthentication getPasswordAuthentication() {
String username = SMTP_AUTH_USER;
String password = SMTP_AUTH_PWD;
return new PasswordAuthentication(username, password);
}
}
// glowna metoda servletu
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
String kod = request.getAttribute("kod");
String aId = request.getAttribute("id");
String msgText = "Twoj kod aktywujacy: " +kod;
msgText += "<BR />Numer zlecenia: "+aId;
msgText += "<BR />http://korporacja.com/aktywacja.jsp";
Message msg = new MimeMessage(sesja);
InternetAddress addressFrom = new InternetAddress(FROM,
"korporacja.com");
try {
msg.setFrom(addressFrom);
InternetAddress to = new InternetAddress(request.getAttribute("email"));
msg.addRecipient(Message.RecipientType.TO, to);
msg.setSubject(temat);
msg.setContent(msgText, "text/html; charset=ISO-8859-2");
Transport.send(msg);
} catch (MessagingException e) {
e.printStackTrace();
}
disp = request.getRequestDispatcher("wyslanoEmail.jsp");
disp.forward(request, response);
return;
}
}
Revise this Paste