Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Java
package sendemail;

import java.util.Properties;
 
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class SendEmail {

    public static void main(String[] args) throws Exception {
        final String username = "Firstemail@yahoo.com";
		final String password = "password";
 
		Properties props = new Properties();
		props.put("mail.smtp.auth", "true");
		props.put("mail.smtp.starttls.enable", "true");
		props.put("mail.smtp.host", "smtp.mail.yahoo.com");
//		props.put("mail.smtp.port", "465");
                	Session session = Session.getInstance(props,
		  new javax.mail.Authenticator() {
			protected PasswordAuthentication getPasswordAuthentication() {
				return new PasswordAuthentication(username, password);
			}
		  });
 
		try {
 
			Message message = new MimeMessage(session);
			message.setFrom(new InternetAddress("Secondemail@yahoo.com"));
			message.setRecipients(Message.RecipientType.TO,
				InternetAddress.parse("Firstemail@yahoo.com"));
			message.setSubject("Testing Subject");
			message.setText("asdasda");
                        
                        
			Transport.send(message);
 
			System.out.println("Done");
 
		} catch (MessagingException e) {
			throw new RuntimeException(e);
		}
    }
    
}


when i have execution this code the recipient email without any text in it....why???
Posted

1 solution

Tutorials
jGuru: Fundamentals of the JavaMail API
[^]

Strange. There should be a text in the body.
Have you seen the raw message? is the text in there?

Please use hmailServer and Thunderbird mobile for testing(both free), that works really well.
 
Share this answer
 
Comments
ahmed tb 23-Aug-12 7:39am    
message.setText("Dear Mail Crawler,"
+ "\n\n No spam to my email, please!");
strange, this body is work
TorstenH. 25-Aug-12 6:54am    
you should use a local environment for testing. You never know how google processes the stuff - you should make it local first.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900