File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes how to send email through servlet using java mail API Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "how to send email through servlet using java mail API" Watch "how to send email through servlet using java mail API" New topic
Author

how to send email through servlet using java mail API

khushi paul
Greenhorn

Joined: Feb 08, 2005
Posts: 26
hi all,
i am trying to send mail through servlet using java mail API.
i get following error

Sending failed; nested exception is: javax.mail.MessagingException: 530 authentication needed

wat shud i do??pls help,as i m new to servlets n mail API
thanks in advance
K Riaz
Ranch Hand

Joined: Jan 08, 2005
Posts: 375
Have you correctly used a valid username and password when connecting to a SMTP server? You could check by telneting to the server.
khushi paul
Greenhorn

Joined: Feb 08, 2005
Posts: 26
thanks 4 ur reply kashif...i m using following code,can u pls tell me where shud i provide username n password..
moreover is it not possible to send mail if i don't know the user name or passwrd of server?is there any way possible?

String host ="my_host_name";
String from = "abc@somename";
String to ="xyz@samename";
String subject = "This is a trial msg!";
String message = "Message comes here!";
Properties prop =System.getProperties();
prop.put("mail.host", host);
Session ses1 = Session.getDefaultInstance(prop,null);
MimeMessage msg = new MimeMessage(ses1);
msg.setFrom(new InternetAddress(from))
msg.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
msg.setSubject(subject);
BodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setText(message);
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);
Transport.send(msg);
Arjun Shastry
Ranch Hand

Joined: Mar 13, 2003
Posts: 1874
You can write a small class which extends javax.mail.Authenticator.Override the method getPasswordAuthentication().Pass the object of the small class:
Session ses1 = Session.getDefaultInstance(prop,new smallClass());
If you download Free SMTP/POP3 server,there is no need to pass Authentication.


MH
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: how to send email through servlet using java mail API
 
Similar Threads
Java Mail in a Web application
javax.mail.Internet.parseException
sending mail with JAVA API
Tracing the anonymous mails
How can I send Xml and Xsl through Java Mail API?