Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <%@ page import="java.io.*,java.util.*,javax.mail.*"%>
- <%@ page import="javax.mail.internet.*,javax.activation.*"%>
- <%@ page import="javax.servlet.http.*,javax.servlet.*"%>
- <%@ page import="java.net.URLConnection,java.net.URL,org.apache.commons.io.IOUtils"%>
- <%
- URL url = new URL("http://fireforwire.appspot.com/Rankings.html");
- URLConnection con = url.openConnection();
- InputStream in = con.getInputStream();
- String encoding = con.getContentEncoding(); // ** WRONG: should use "con.getContentType()" instead but it returns something like "text/html; charset=UTF-8" so this value must be parsed to extract the actual encoding
- encoding = encoding == null ? "UTF-8" : encoding;
- String body = IOUtils.toString(in, encoding);
- System.out.println(body);
- %>
- <%
- out.println("Result: " + body + "n");
- %>
- <%
- String result;
- Properties props = new Properties();
- props.put("mail.smtp.auth", "true");
- //props.put("mail.smtp.starttls.enable", "true");
- props.put("mail.smtp.host", "smtp.gmail.com");
- props.put("mail.smtp.port", "465");
- props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
- Session session1 = Session.getInstance(props,
- new javax.mail.Authenticator() {
- protected PasswordAuthentication getPasswordAuthentication() {
- return new PasswordAuthentication("sasipudi@gmail.com", "****");
- }
- });
- try {
- Message message = new MimeMessage(session1);
- message.setFrom(new InternetAddress("sasipudi@gmail.com"));
- message.setRecipients(Message.RecipientType.TO,
- InternetAddress.parse("sasipudi@gmail.com"));
- message.setSubject("Testing Subject");
- message.setContent(body, "text/html");
- Transport.send(message);
- System.out.println("Done");
- result="sent succesful";
- } catch (MessagingException e) {
- throw new RuntimeException(e);
- }
- %>
- <%
- out.println("Result: " + result + "n");
- %>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement