Advertisement
Advertisement
| 05.19.2008 at 02:47AM PDT, ID: 23413101 |
|
[x]
Attachment Details
|
||
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: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: |
import myMail.*;
import java.util.*;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@SuppressWarnings("serial")
public class MailServlet extends HttpServlet{
protected void doGet( HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
MyMail m = new MyMail();
String recipients = "hihi@gmail.com";
String subject = "hi test";
String message = "<html>testing"</html>";
String from = "lol@test.com";
m.postMail(recipients, subject, message, from);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
}
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
public class MyMail{
public void postMail( String recipients, String subject,
String message , String from)
{
try {
final String SMTP_HOST_NAME = "mail.gilim.net";
boolean debug = false;
//Set the host smtp address
Properties props = new Properties();
props.put("mail.smtp.host", SMTP_HOST_NAME);
props.put("mail.smtp.auth", "true");
Authenticator auth = new SMTPAuthenticator();
Session session = Session.getDefaultInstance(props, auth);
session.setDebug(debug);
// create a message
Message msg = new MimeMessage(session);
// set the from and to address
InternetAddress addressFrom = new InternetAddress(from);
msg.setFrom(addressFrom);
InternetAddress[] addressTo = new InternetAddress[recipients.length()];
msg.setRecipients(Message.RecipientType.TO, addressTo);
// Setting the Subject and Content Type
msg.setSubject(subject);
msg.setContent(message, "text/plain");
Transport.send(msg);
} catch (MessagingException e) {
e.printStackTrace();
}
}
}
package MyMail;
import javax.mail.PasswordAuthentication;
public class SMTPAuthenticator extends javax.mail.Authenticator
{
public PasswordAuthentication getPasswordAuthentication()
{
String username = "testuser@mydomain.net";
String password = "test";
return new PasswordAuthentication(username, password);
}
}
|