• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

javaMail with google..

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to send mail using JAVAMAIL API with GMAIL SMTP
using this code in a servlet..


and evrytime i got this error>>

com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Authentication Required m1sm854399ugc

///
package com.mail;

import java.io.IOException;
import java.security.Security;
import java.util.Properties;
import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class serv1 extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response)throws IOException
{

String to= (String)request.getParameter("to");
String subject= (String)request.getParameter("subject");
String msgContent = tring)request.getParameter("msgContent");

try
{
Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
Properties prop = new Properties();


prop.put("mail.transport.protocol", "smtp");
prop.put("mail.smtp.host", "smtp.gmail.com");
prop.put( "mail.smtp.auth ", "true");
prop.put("mail.debug", "true");
prop.put("mail.smtp.port", "465");
prop.put("mail.smtp.starttls.enable","true");
prop.put("mail.smtp.socketFactory.port", "465");
prop.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
prop.put("mail.smtp.socketFactory.fallback", "false");

Session session = Session.getDefaultInstance(prop,
new ForcedAuthenticator());
session.setDebug(true);
MimeMessage msg = new MimeMessage(session);

InternetAddress addressFrom = new InternetAddress("redacted@gmail.com", "redacted@gmail.com");
msg.setFrom(addressFrom);
InternetAddress addressTo = new InternetAddress(to);
msg.setRecipient(Message.RecipientType.TO, addressTo);

msg.setSubject(subject);
msg.addHeader("HEADER", "Razi header ");
msg.setContent(msgContent, "text/html");
Transport.send(msg);

response.sendRedirect("/pages/email.jsp");
}
catch (Exception e)
{
e.printStackTrace();
}

}
}
class ForcedAuthenticator extends Authenticator {
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("myUserName",
"myPassword");
}
}
 
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I do not see that you setup in properties user name and password. I think these values will be
"mail.smtp.password"
and "mail.smtp.user"
Just found them using MSN search. I use light e-mail sender in my jAddressBook project and it works quite well with google SMTP.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic