我试图使用Java Mail API发送电子邮件. [英] im trying to send email using java mail API.

查看:112
本文介绍了我试图使用Java Mail API发送电子邮件.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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???

推荐答案

^ ]

奇怪的.正文中应该有文字.
您看到原始消息了吗?里面有文字吗?

请使用hmailServer和Thunderbird mobile进行测试(均为免费),效果非常好.
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.


这篇关于我试图使用Java Mail API发送电子邮件.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆