GeSHi (geshi):
<%@ page import="javax.mail.PasswordAuthentication,java.uti l.Date,java.util.Properties,javax.activation.DataH andler,javax.activation.FileDataSource,javax.mail. Message,javax.mail.MessagingException,javax.mail.M ultipart,javax.mail.Session,javax.mail.Transport,j avax.mail.internet.InternetAddress,javax.mail.inte rnet.MimeBodyPart,javax.mail.internet.MimeMessage, javax.mail.internet.MimeMultipart" %>
<%
String from = "abcd@gmail.com";
String to[] = {"abcd@gmail.com"};
String subject = "Password Recovery";
String bodyText = "The information contained in this electronic message and any attachments to this message are intended for exclusive use of the addressee(s) and may contain confidential or privileged information. If you are not the intended recipient, please notify the sender at xyz@mycony.com immediately and destroy all copies of this message and any attachments. The views expressed in this E-mail message / Attachments, are those of the individual sender.";
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.auth", "true");
props.put("mail.debug", "true");
props.put("mail.smtp.port", "465");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.socketFactory.fallback", "false");
Session s = Session.getDefaultInstance(props,new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("abcd@gmail.com", "pwd1234");
}
});
try {
MimeMessage message = new MimeMessage(s);
message.setFrom(new InternetAddress(from));
for(int i=0;i<to.length;i++){
message.setRecipient(Message.RecipientType.TO, new InternetAddress(to[i]));
message.setSubject(subject);
message.setSentDate(new Date());
//
// Set the email message text.
//
MimeBodyPart messagePart = new MimeBodyPart();
messagePart.setText(bodyText);
//
// Set the email attachment file
//
/*MimeBodyPart attachmentPart = new MimeBodyPart();
FileDataSource fileDataSource = new FileDataSource(filename) {
@Override
public String getContentType() {
return "application/octet-stream";
}
};
attachmentPart.setDataHandler(new DataHandler(fileDataSource));
attachmentPart.setFileName(filename);*/
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messagePart);
// multipart.addBodyPart(attachmentPart);
message.setContent(multipart);
Transport.send(message);
}
} catch (MessagingException e) {
e.printStackTrace();
}
%>
Created by GeSHI 1.0.7.20
When i run this code first time it works perfect and 2nd time it gives error:
Access to default session denied
Thanks and Regards,