javax.mail.NoSuchProviderException: smtp -Java Mail Problem
843830Oct 13 2005 — edited Mar 29 2007Sorry for starting a new thread for this . But I am unable to resolve this prob.
I am using WSAD 5.0 and struts 1.2 and not able to send the email
Here is my code and exception. Pls help if you can. Thanks!
package com.dcs.mcass.domain;
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;
import javax.naming.*;
import javax.activation.*;
/**
* @author t4263sa
*
* To change this generated comment edit the template variable "typecomment":
* Window>Preferences>Java>Templates.
* To enable and disable the creation of type comments go to
* Window>Preferences>Java>Code Generation.
*/
public class EmailUtility {
private static final Properties props = System.getProperties();
static{
props.put("mail.smtp.host", EmailInfo.EMAIL_HOST);
}
public static void sendEmail(EmailInfo emailInfo){
String from = null;
String to = null;
String cc = null;
String subject = null;
String custText = null;
String messageString = null;
StringBuffer messageBuffer = null;
int index = 0;
String emailDomain = EmailInfo.EMAIL_DOMAIN;
Session session = Session.getDefaultInstance(props);
try{
MimeMessage message = new MimeMessage(session);
from = emailInfo.getFrom();
if (from != null) {
message.setFrom(new InternetAddress(from + emailDomain));
}
else
{
throw new Exception("From is mandatory");
}
to = emailInfo.getTo();
if (to != null) {
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to + emailDomain));
}
else
{
throw new Exception("To is mandatory");
}
cc = emailInfo.getCc();
if (cc != null){
message.addRecipient(Message.RecipientType.CC, new InternetAddress(cc + emailDomain));
}
subject = emailInfo.getSubject();
if (subject != null) {
message.setSubject(subject);
// Create the message part
BodyPart messageBodyPart = new MimeBodyPart();
//get the message based on Process
messageString = emailInfo.getCustText();
// Fill the message
messageBodyPart.setText(messageString);
System.out.println("after setting the msg");
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);
// Put parts in message
message.setContent(multipart);
//Transport transport = session.getTransport();
//transport.connect();
// Send the message
Transport.send(message);
//transport.sendMessage(message,
// message.getRecipients(Message.RecipientType.TO));
//transport.close();
}
else
{
throw new Exception("subject is mandatory");
}
}catch(Exception e ){
System.out.println("Exception e = " + e.toString() + " " + e.getMessage());
}
}
public static void main(String args[]) throws Exception {
String to = "sa36" ;
String from = "sa36" ;
String cc = "sa36";
System.out.println("Before send Mail");
EmailInfo emailInfo = new EmailInfo();
emailInfo.setFrom(from);
emailInfo.setTo(to);
emailInfo.setCc(cc);
emailInfo.setSubject("java util");
emailInfo.setCustText("Testing Testing");
System.out.println("emailInfo = " + emailInfo.toString());
EmailUtility.sendEmail(emailInfo);
System.out.println("After send Mail");
}
}
Exception : javax.mail.NoSuchProviderException: smtp