Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how to send email through servlet using java mail API  RSS feed

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);
 
Ranch Hand
Posts: 1907
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Come have lunch with me Arthur. Adventure will follow. This tiny ad:
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!