i want to send mail through from my website. i used the below code
String host="smtp.gmail.com",
user="username",
pass="password";
//host = smtp_server; //"smtp.gmail.com"; user = jsp_email; //"YourEmailId@gmail.com" // email id to send the emails
//pass = jsp_email_pw; //Your gmail password
String SSL_FACTORY ="javax.net.ssl.SSLSocketFactory";
String to = email;// out going email id
String from ="emailid"; //Email id of the recipient
String subject ="Account Information";
String messageText ="hi";
boolean sessionDebug = true;
Properties props = System.getProperties();
props.put("mail.host", host);
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "465");
props.put("mail.debug", "true");
props.put("mail.smtp.socketFactory.fallback", "false");
props.put("mail.smtp.socketFactory.class", SSL_FACTORY);
Session mailSession = Session.getDefaultInstance(props,null);
mailSession.setDebug(sessionDebug);
Message msg =new MimeMessage(mailSession);
try
{
msg.setFrom(new InternetAddress(from));
InternetAddress[] address = {new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject(subject);
msg.setContent(messageText,"text/html"); // use setText if you want to send text
Transport transport = mailSession.getTransport("smtp");
transport.connect(host, user, pass);
transport.sendMessage(msg, msg.getAllRecipients());
/
//WasEmailSent = true; // assume it was sent
transport.close();
}
catch
(Exception err) {
//WasEmailSent = false; // assume it's a fail
out.println("Error"+err.getMessage());
}
it worked fine with my friends system. but i get the below error
Loading javamail.default.providers from jar:file:/H:/dinesh/wasce with java1.5/wasce with java1.5/repository/default/darkhorse/1.0/darkhorse-1.0.car/WEB-INF/lib/mail.jar!/META-INF/javamail.default.providers
DEBUG: loading new provider protocol=imap, className=com.sun.mail.imap.IMAPStore, vendor=Sun Microsystems, Inc, version=null
DEBUG: loading new provider protocol=smtp, className=com.sun.mail.smtp.SMTPTransport, vendor=Sun Microsystems, Inc, version=null
DEBUG: loading new provider protocol=pop3, className=com.sun.mail.pop3.POP3Store, vendor=Sun Microsystems, Inc, version=null
DEBUG: getProvider() returning provider protocol=smtp; type=javax.mail.Provider$Type@25a225a2; class=com.sun.mail.smtp.SMTPTransport; vendor=Sun Microsystems, Inc
DEBUG SMTP: useEhlo true, useAuth true
DEBUG: SMTPTransport trying to connect to host "smtp.gmail.com", port 465
DEBUG SMTP RCVD:
DEBUG: SMTPTransport could not connect to host "smtp.gmail.com", port: 465
we both use the same providers...
i have turned of the firewall and even uninstalled the anti virus....
i have got struck in this for one week
plz help me out from this....