• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

how to send email through servlet using java mail API

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
A wop bop a lu bob a womp bam boom. Tutti frutti ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic