• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

javaMail with google..

Rob Qas
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • 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");

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.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());
MimeMessage msg = new MimeMessage(session);

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

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

catch (Exception e)

class ForcedAuthenticator extends Authenticator {
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("myUserName",
dema rogatkin
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I do not see that you setup in properties user name and password. I think these values will be
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.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic