dcsimg
Strange problem sending mail with jsp
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   sarantos_michalarias
Posted On:   Tuesday, April 30, 2002 12:57 AM

Hello! I found in faq how to send an email from providers who need pop authentication (the example uses yahoo). I am using as provider HOTPOP. When i run the jsp page for first time i get pop authentication error. If I refresh the page everything is OK! What can be wrong? Here is the code i am using! Thanks in advance. Sarantos String smtpHost = "smtp.hotpop.com"; String popHost = "pop.hotpop.com"; String from = "myaccount@hotpop.com"; String to = "myaccount@hotmail.com"; String username = "myusername"; String password = "mypassword";    More>>

Hello! I found in faq how to send an email from providers who need pop authentication (the example uses yahoo). I am using as provider HOTPOP. When i run the jsp page for first time i get pop authentication error. If I refresh the page everything is OK! What can be wrong?
Here is the code i am using!
Thanks in advance.
Sarantos






String smtpHost = "smtp.hotpop.com";

String popHost = "pop.hotpop.com";

String from = "myaccount@hotpop.com";

String to = "myaccount@hotmail.com";

String username = "myusername";

String password = "mypassword";


// Get system properties

Properties props = System.getProperties();


// Setup mail server

props.put("mail.smtp.host", smtpHost);


// Get session


Session ses = Session.getDefaultInstance(props, null);

ses.setDebug(true);


// Pop Authenticate yourself

Store store = ses.getStore("pop3");

try

{

store.connect(popHost, username, password);

}

catch(javax.mail.AuthenticationFailedException ex)

{

out.print("error");

}

// Define message

MimeMessage message = new MimeMessage(ses);

message.setFrom(new InternetAddress(from));

message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));

message.setSubject("Image mail");


// Create your new message part

BodyPart messageBodyPart = new MimeBodyPart();

String htmlText = "

Hello

";

messageBodyPart.setContent(htmlText, "text/html");


// Create a related multi-part to combine the parts

MimeMultipart multipart = new MimeMultipart("related");

multipart.addBodyPart(messageBodyPart);


// Create part for the image

messageBodyPart = new MimeBodyPart();


// Fetch the image and associate to part

DataSource fds = new FileDataSource
("C:/tomcat/webapps/examples/jsp/cal/file1.gif");

messageBodyPart.setDataHandler(new DataHandler(fds));

messageBodyPart.setHeader("Content-ID","memememe");


// Add part to multi-part

multipart.addBodyPart(messageBodyPart);


// Associate multi-part with message

message.setContent(multipart);



// Send message

Transport.send(message);

   <<Less
About | Sitemap | Contact