participate


JavaMail - Javamail using Gmail SMTP 465 port!
<<   Back to Forum  |   Give us Feedback
10 Duke Stars available
This topic has 37 replies on 3 pages.    1 | 2 | 3 | Next »
vzkat007
Posts:2
Registered: 9/28/05
Javamail using Gmail SMTP 465 port!   
Sep 30, 2005 8:39 AM

 
I am trying to send mail using JAVAMAIL API with GMAIL SMTP on port 465.
Now, I setup my outlook smtp.gmail.com with port 465 and I was able to send e-mail using outlook. So, I am sure it can be done using javamail as well. However, when I tried the same with javamail, I keep getting the following authentication error: Coud someone please let mne know how to get rid of this error and make my code work?I appreciate your help.

Thanks,
Venkat

Error:

DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Su
n Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth false
DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 465, isSSL false
220 mx.gmail.com ESMTP i20sm2352180wxd
DEBUG SMTP: connected to host "smtp.gmail.com", port: 465

EHLO vkat
250-mx.gmail.com at your service
250-SIZE 20971520
250-8BITMIME
250-AUTH LOGIN PLAIN
250 ENHANCEDSTATUSCODES
DEBUG SMTP: Found extension "SIZE", arg "20971520"
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "AUTH", arg "LOGIN PLAIN"
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: use8bit false
MAIL FROM:<vkat007@gmail.com>
530 5.7.0 Authentication Required i20sm2352180wxd
com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Authentication Required i20sm2352180wxd
at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1333)

Following is the snippet of my code:

Properties p = new Properties();
p.put("mail.smtp.user", "vkat007@gmail.com");
p.put("mail.smtp.host", mailhost);
p.put("mail.smtp.port", "465");
p.put("mail.smtp.starttls.enable","true");
p.put( "mail.smtp.auth ", "true ");
p.put("mail.smtp.debug", "true");
p.put("mail.smtp.socketFactory.port", "465");
p.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
p.put("mail.smtp.socketFactory.fallback", "false");


SecurityManager security = System.getSecurityManager();
System.out.println("Security Manager" security);


try {
Authenticator auth = new SMTPAuthenticator();
Session session = Session.getInstance(p, auth);
session.setDebug(true);

//session = Session.getDefaultInstance(p);
MimeMessage msg = new MimeMessage(session);
msg.setText(text);
msg.setSubject(subject);
Address fromAddr = new InternetAddress("vkat007@gmail.com");
msg.setFrom(fromAddr);
Address toAddr = new InternetAddress(_to);
msg.addRecipient(Message.RecipientType.TO, toAddr);
System.out.println("Message: "
msg.getContent());
Transport.send(msg);
}
catch (Exception mex) { // Prints all nested (chained) exceptions as well
System.out.println("I am here??? ");
mex.printStackTrace();
}
}

private class SMTPAuthenticator extends javax.mail.Authenticator {

public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("vkat007@gmail.com", "xxxxxxxxxxx"); // password not displayed here, but gave the right password in my actual code.
}
}
 
sohail_shaikh
Posts:4
Registered: 9/19/05
Re: Javamail using Gmail SMTP 465 port!   
Oct 3, 2005 3:23 AM (reply 1 of 37)  (In reply to original post )

 
return new PasswordAuthentication("vkat007@gmail.com", "xxxxxxxxxxx");
instead to typing your complete email address try
typing your userid and password. then execute the code.
return new PasswordAuthentication("vkat007", "xxxxxxxxxxx");
 
vzkat007
Posts:2
Registered: 9/28/05
Re: Javamail using Gmail SMTP 465 port!   
Oct 3, 2005 5:59 AM (reply 2 of 37)  (In reply to #1 )

 
Tried that but no luck!!
 
Vigu
Posts:1
Registered: 5/23/05
Re: Javamail using Gmail SMTP 465 port!   
Dec 8, 2005 5:35 AM (reply 3 of 37)  (In reply to original post )

 
There is a space issue
remove the space after "mail.smtp.auth " and after "true "

p.put("mail.smtp.auth ", "true ");
p.put("mail.smtp.auth", "true");] // replace the above line with this
 
jayaprabhakar
Posts:7
Registered: 1/17/05
Re: Javamail using Gmail SMTP 465 port!   
Jan 10, 2006 9:49 AM (reply 4 of 37)  (In reply to #3 )

 
I am also facing the same problem. Have u found the solution. Please reply me if u have solved it.
Thanks.

Does it require any other configurations to make this work?
 
ade
Posts:1
Registered: 1/21/06
Re: Javamail using Gmail SMTP 465 port!   
Jan 21, 2006 11:48 PM (reply 5 of 37)  (In reply to original post )

 
Venkat,

Thanks your code helped me to get connected to the gmail smtp server very quickly.

Use:

p.put( "mail.smtps.auth ", "true ");

(with the extra s) and it will work.

Ade
 
dchagastelles
Posts:1
Registered: 1/30/06
Re: Javamail using Gmail SMTP 465 port!   
Jan 30, 2006 4:53 AM (reply 6 of 37)  (In reply to #5 )

 
can u post your code, please. I cant connect to the server.
 
BenThoma
Posts:19
Registered: 8/8/05
Re: Javamail using Gmail SMTP 465 port!   
Nov 7, 2006 3:04 PM (reply 7 of 37)  (In reply to #5 )

 
System.setProperty("mail.smtps.auth", "true");

Was what worked for me. Thanks!
 
nadh
Posts:1
Registered: 4/11/07
Re: Javamail using Gmail SMTP 465 port!   
Apr 11, 2007 6:10 AM (reply 8 of 37)  (In reply to #7 )

 
Hi.. This is the out put i am getting.

com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Must issue a STARTTLS command first y11sm590283pod


Also...Is there any way that i cans send mails to mail addresses on some other domain??

nadh
 
bshannon
Posts:4,225
Registered: 10/27/97
Re: Javamail using Gmail SMTP 465 port!   
Apr 11, 2007 9:28 AM (reply 9 of 37)  (In reply to #8 )

 
The JavaMail FAQ has details on connecting to Gmail.

You can enable use of STARTTLS by setting the session property
"mail.smtp.starttls.enable" to "true".
 
Shawky.Foda
Posts:1
Registered: 11/8/07
Re: Javamail using Gmail SMTP 465 port!   
Nov 8, 2007 4:29 AM (reply 10 of 37)  (In reply to #5 )

 
Could You Please send me complete code.

Thanks
 
bshannon
Posts:4,225
Registered: 10/27/97
Re: Javamail using Gmail SMTP 465 port!   
Nov 8, 2007 9:58 AM (reply 11 of 37)  (In reply to #10 )

 
You have the complete code. It's included with the
JavaMail download bundle. Use the instructions in the
FAQ to invoke the demo programs with the correct
parameters and it will work.
 
fantastic_ray
Posts:51
Registered: 11/5/07
Re: Javamail using Gmail SMTP 465 port!   
Dec 1, 2007 11:56 PM (reply 12 of 37)  (In reply to original post )

 
This code works perfectly fine to send mail from gmail.


import java.security.Security;
import java.util.Properties;
 
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;
 
 
public class SimpleMail 
{
	private String mailhost = "smtp.gmail.com";
	
	public synchronized void sendMail(String subject, String body, String sender, String recipients) 
																				   throws Exception 
	{	
		
		Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
		 
		Properties props = new Properties();
		props.setProperty("mail.transport.protocol", "smtp");
		props.setProperty("mail.host", mailhost);
		props.put("mail.smtp.auth", "true");
		props.put("mail.smtp.port", "465");
		props.put("mail.smtp.socketFactory.port", "465");
		props.put("mail.smtp.socketFactory.class",
		"javax.net.ssl.SSLSocketFactory");
		props.put("mail.smtp.socketFactory.fallback", "false");
		props.setProperty("mail.smtp.quitwait", "false");
 
		Session session = Session.getDefaultInstance(props,
				new javax.mail.Authenticator() 
		{
			protected PasswordAuthentication getPasswordAuthentication()
			{ return new PasswordAuthentication("username","password");	}
		});		
 
		MimeMessage message = new MimeMessage(session);
		message.setSender(new InternetAddress(sender));
		message.setSubject(subject);
		message.setContent(body, "text/plain");
		if (recipients.indexOf(',') > 0) 
					message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipients));
		else
					message.setRecipient(Message.RecipientType.TO, new InternetAddress(recipients));
 
		
		Transport.send(message);
		
	}
	
	
	public static void main(String args[]) throws Exception
	{
		MailUtils mailutils = new MailUtils();
		mailutils.sendMail("test", "test", "from@gmail.com", "To@gmail.com");
		
	}
	
}
 
fantastic_ray
Posts:51
Registered: 11/5/07
Re: Javamail using Gmail SMTP 465 port!   
Dec 1, 2007 11:57 PM (reply 13 of 37)  (In reply to #12 )

 
can I get my duke starts please ;)
 
kasun_kandy
Posts:4
Registered: 3/22/07
Re: Javamail using Gmail SMTP 465 port!   
Dec 2, 2007 7:16 AM (reply 14 of 37)  (In reply to #13 )

 
thankx fantastic_ray your code works. it was very useful
 
This topic has 37 replies on 3 pages.    1 | 2 | 3 | Next »
Back to Forum
 
Read the Developer Forums Code of Conduct

Click to email this message Email this Topic

Edit this Topic
  
 
 
Forums Statistics
    Users Online : 26
  • Guests : 122

About Sun forums
  • Sun Forums is a large collection of user generated discussions. It is here to help you ask questions, find answers, and participate in discussions.

    Check out our guide on Getting started with Sun Forums for a full walkthrough of how to best leverage the benefits of this community.

Powered by Jive Forums