Re: Error when sending mail
Posted By:
Anonymous
Posted On:
Monday, January 12, 2004 09:50 PM
you should requied mail authentication?try to authenticate
Re: Error when sending mail
Posted By:
Anonymous
Posted On:
Monday, January 12, 2004 07:59 PM
package name;
import javax.mail.Authenticator;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.Multipart;
import javax.mail.Message;
import javax.mail.BodyPart;
import javax.mail.Message.RecipientType;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMultipart;
import javax.mail.internet.InternetAddress;
import java.util.Properties;
public class Mailer
{
public String mimeType;
private MimeMessage message;
public void setSession(){
Properties props = new Properties();
JAuthenticate pAuth = new JAuthenticate();
props.put("mail.smtp.host", "mail.address");
props.put("mail.smtp.auth", "true");
Session s = Session.getInstance(props, pAuth);
message = new MimeMessage(s);
}
public void setRecipients(String[] toWhom) throws javax.mail.MessagingException{
for(int i=0; i message.setRecipients(Message.RecipientType.TO,InternetAddress.parse(toWhom[i]));
}
}
public void setSubject(String subject) throws javax.mail.MessagingException{
message.setSubject(subject);
}
public void setMimeType(String mimeType) throws javax.mail.MessagingException{
this.mimeType = mimeType;
}
public void setContent(String content) throws javax.mail.MessagingException{
BodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setContent(content,"text/html");
MimeMultipart multipart= new MimeMultipart("alternative");
multipart.addBodyPart(messageBodyPart);
message.setContent(multipart);
}
public void setFrom() throws javax.mail.MessagingException{
message.setFrom(new InternetAddress("admin@icmspot.com"));
}
public void setFrom(String from) throws javax.mail.MessagingException{
message.setFrom(new InternetAddress(from));
}
public void addAttachment(File file)
{
String contentType = message.getContentType();
if (contentType.indexOf("multipart/mixed")>=0)
{
for (int m=0; m {
BodyPart bp = multipart.getBodyPart(m);
String attachmentName = bp.getFileName("ss.jsp");
//process attachment
}
}
}
public void removeAttachment(int position)
{
}
public void removeAllAttachments()
{
}
public int getAttachmentsCount()
{
String contentType = message.getContentType();
if (contentType.indexOf("multipart/mixed")>=0)
{
for (int m=0; m {
BodyPart bp = multipart.getBodyPart(m);
String attachmentName = bp.getFileName("ss.jsp");
//process attachment
}
}
}
public void send() throws javax.mail.MessagingException{
Transport.send(message);
}
} // class