Click here to Skip to main content
       

Java

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
Questionjava TLS Sending Emailmemberrenishkhunt2 Jan '13 - 18:52 
import javax.mail.*;
import javax.mail.Message;
import java.util.*;
import javax.mail.internet.*;
 
public class Sendemail {
 
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
            final String username="username";
            final String password="password";
            Properties prop=new Properties();
            prop.put("mail.smtp.auth", "true");
            prop.put("mail.smtp.host", "smtp.gmail.com");
            prop.put("mail.smtp.port", "587");
            prop.put("mail.smtp.starttls.enable", "true");
        
            Session session = Session.getDefaultInstance(prop,
		  new javax.mail.Authenticator() {
			protected PasswordAuthentication getPasswordAuthentication() {
				return new PasswordAuthentication(username, password);
			}
		  });
          try {
 
			Message message = new MimeMessage(session);
			message.setFrom(new InternetAddress("myemail@gmail.com"));
			message.setRecipients(Message.RecipientType.TO,
				InternetAddress.parse("receiveremail@gmail.com"));
			message.setSubject("Testing Subject");
			message.setText("Dear Mail Crawler,sNo spam to my email, please!");
                       
			Transport.send(message);
 
			System.out.println("Done");
 
		} catch (MessagingException e) {
			e.printStackTrace();
		}
            
    }
}
 

 

Please Help Someone..
    I have Exception On this code
 
javax.mail.MessagingException: 502 5.5.1 Unrecognized command. nw9sm29708787pbb.42
 
	at com.sun.mail.smtp.SMTPTransport.issueCommand(SMTPTransport.java:2080)
	at com.sun.mail.smtp.SMTPTransport.startTLS(SMTPTransport.java:1910)
	at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:652)
	at javax.mail.Service.connect(Service.java:317)
	at javax.mail.Service.connect(Service.java:176)
	at javax.mail.Service.connect(Service.java:125)
	at javax.mail.Transport.send0(Transport.java:194)
	at javax.mail.Transport.send(Transport.java:124)
	at sendemail.Sendemail.main(Sendemail.java:44)
 


AnswerRe: java TLS Sending EmailmemberPhat (Phillip) H. VU2 Jan '13 - 22:08 
Hi renishkhunt,
 
Check it out :
java TLS Sending Email[^]
GeneralRe: java TLS Sending Emailmemberrenishkhunt2 Jan '13 - 23:26 
 Dear Phat (Phillip) H. VU
                 I use your code that is generate Exception that like
 
 
javax.mail.MessagingException: IOException while sending message;
  nested exception is:
        javax.activation.UnsupportedDataTypeException: no object DCH for MIME type text/plain; charset=us-ascii
        at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:676)
        at javax.mail.Transport.send0(Transport.java:189)
        at javax.mail.Transport.send(Transport.java:118)
        at semdemail.Main.main(Main.java:46)
Caused by: javax.activation.UnsupportedDataTypeException: no object DCH for MIME type text/plain; charset=us-ascii
        at javax.activation.ObjectDataContentHandler.writeTo(DataHandler.java:870)
        at javax.activation.DataHandler.writeTo(DataHandler.java:301)
        at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1403)
        at javax.mail.internet.MimeMessage.writeTo(MimeMessage.java:1745)
        at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:636)
        ... 3 more 

GeneralRe: java TLS Sending Email [modified]memberPhat (Phillip) H. VU3 Jan '13 - 0:12 
Hi renishkhunt,
 
I've re-tested the code in my answer at java TLS Sending Email[^]. And it run as well( using gmail account to send test email to another gmail account).
 
Updated : I've test my demo on JDK 1.5, 1.6, 1.7 ; sending email from Gmail to another mail service, such as Hotmail.It run as well. Wink | ;)
 
You can download my demo at http://sdrv.ms/VxAqON[^]

modified 3 Jan '13 - 6:21.

GeneralRe: java TLS Sending EmailmemberPhat (Phillip) H. VU3 Jan '13 - 20:09 
You might probably to check the proxy... Hmm.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   


Advertise | Privacy | Mobile
Web04 | 2.6.130523.1 | Last Updated 23 May 2013
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid