Posted By:
Arun_Singh
Posted On:
Wednesday, April 30, 2008 06:18 AM
I am working on a site . In that there is an option for sending the mail . But i got javax.mail.AuthenticationFailedException when i send the mail. But it works sometimes and it fails sometimes automaticallly. I am sure that there i sno problem in my mailing code. I contacted the person which provide the webhosting service for the my wesite. He said it is the problem from your side . I am in confusion . what is the problem . I do not use any user id and password My code is import javax.mail.internet.*; import javax.activation.*; import java.util.Propertie
More>>
I am working on a site . In that there is an option for sending the mail .
But i got javax.mail.AuthenticationFailedException when i
send the mail.
But it works sometimes and it fails sometimes
automaticallly.
I am sure that there i sno problem in my mailing code.
I contacted the person which provide the webhosting service for the my wesite.
He said it is the problem from your side . I am in confusion . what is the problem .
I do not use any user id and password
My code is
import javax.mail.internet.*;
import javax.activation.*;
import java.util.Properties;
import sun.net.smtp.SmtpClient;
public class SendMailBean {
String smtpHost = "localhost";
String contenttype = "text/plain";
public String send(String p_from, String p_to, String
p_cc, String p_bcc, String p_subject, String p_message,
String p_smtpServer, String contenttype)
{
try
{
if(contenttype!=null)
{
this.contenttype = contenttype;
}
Properties prop = System.getProperties();
prop.put("mail.smtp.host",smtpHost);
Session ses = Session.getInstance(prop,null);
MimeMessage message = new MimeMessage(ses);
message.setFrom(new InternetAddress(p_from));
message.setRecipient(Message.RecipientType.TO,new
InternetAddress(p_to));
if(p_cc != null)
{
message.setRecipient(Message.RecipientType.CC,new
InternetAddress(p_cc));
}
if(p_bcc != null)
{
message.setRecipient(Message.RecipientType.BCC,new
InternetAddress(p_bcc));
}
message.setSubject(p_subject);
message.setContent(p_message,this.contenttype);
Transport.send(message);
return "success";
}
catch(Exception e)
{
return e.toString();
}
}
}
<<Less