sendEmail problem
I want to send email from a server using smtp protocol. This server has a user name and a password. I have some problems :
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: javax.mail.NoSuchProviderException: Invalid protocol: null
org.apache.struts.action.RequestProcessor.processE xception(RequestProcessor.java:535)
Code :
if (Rs != null && Rs.next())
{
Properties props = new Properties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.host", "mail.eurosystemsdevelopment.com");
props.put("auth", "true");
SMTPAuthenticator sm = new SMTPAuthenticator("ggg@jjjjjj.com","werwerwer");
Session mailSession = Session.getDefaultInstance(props,sm);
Transport transport = mailSession.getTransport();
MimeMessage message = new MimeMessage(mailSession);
message.setContent("Your password is " + Rs.getString("Password"), "text/plain");
message.setFrom(new InternetAddress("xxx@yyyy.com"));
message.addRecipient(Message.RecipientType.TO,
new InternetAddress(f.getUserEmail()));
transport.connect();
transport.sendMessage(message,
message.getRecipients(Message.RecipientType.TO));
transport.close();
request.setAttribute("emailSent", "Email was sent succesfully");
}
the SMTPAuthenticator class :
import javax.mail.PasswordAuthentication;
public class SMTPAuthenticator extends javax.mail.Authenticator {
String username;
String password;
public SMTPAuthenticator(String username, String password)
{
this.username = username;
this.password = password;
}
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(this.username, this.password);
}
}
Any ideas? Thank you
__________________
Thank you
|