java邮箱发送不出去_java mail问题,邮件发不出去,请教高手!!!!!!

我的程序代码如下:importjavax.mail.internet.InternetAddress;importjavax.mail.internet.MimeMessage;importjava.util.Properties;importjavax.mail.Session;importjava.io.FileOu...

我的程序代码如下:

import javax.mail.internet.InternetAddress;

import javax.mail.internet.MimeMessage;

import java.util.Properties;

import javax.mail.Session;

import java.io.FileOutputStream;

import javax.activation.FileDataSource;

import javax.activation.DataHandler;

import javax.mail.internet.MimeBodyPart;

import javax.mail.internet.MimeMultipart;

import javax.mail.Message;

import javax.mail.Transport;

public class HtmlMessageSender

{

String protocol = "smtp";

String from = "lebrondomiante@sina.cn";

String to = "这里写的是我的一个gmail账户";

String subject = "test";

String body = "Hello!!"+

"%5C%22cid:LEBRON%5C%22";

public static void main(String[] args) throws Exception

{

String server = "smtp.sina.com.cn";

String user = "我的用户名";

String pass = "我的密码";

HtmlMessageSender sender = new HtmlMessageSender ();

Session session = sender.createSession();

MimeMessage message = sender.createMessage(session);

Transport transport = session.getTransport();

transport.connect(server, user, pass);

transport.sendMessage(message,message.getRecipients(Message.RecipientType.TO));

transport.close();

}

public Session createSession()

{

Properties props = new Properties();

props.setProperty("mail.transport.protocol", protocol);

props.setProperty("mail.smtp.auth","true");

Session session = Session.getInstance(props);

session.setDebug(true);

return session;

}

public MimeMessage createMessage(Session session) throws Exception

{

MimeMessage message = new MimeMessage(session);

message.setFrom(new InternetAddress(from));

message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to));

message.setSubject(subject);

MimeMultipart multipart = new MimeMultipart("related");

MimeBodyPart htmlBodyPart = new MimeBodyPart();

htmlBodyPart.setContent(body, "text/html;charset=gb2312");

multipart.addBodyPart(htmlBodyPart);

MimeBodyPart gifBodyPart = new MimeBodyPart();

FileDataSource fds = new FileDataSource("E:\\lebron james\\images.jpg");

gifBodyPart.setDataHandler(new DataHandler(fds));

gifBodyPart.setContentID("LEBRON");

multipart.addBodyPart(gifBodyPart);

message.setContent(multipart);

message.saveChanges();

return message;

}

}

然后运行后出错:

535 #5.7.0 Authentication failed

Exception in thread "main" javax.mail.AuthenticationFailedException

at javax.mail.Service.connect(Service.java:319)

at javax.mail.Service.connect(Service.java:169)

at HtmlMessageSender.main(HtmlMessageSender.java:33)

请教高手是哪里出了问题,我现在人在澳大利亚,这个和我不在国内有关系吗?

展开

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值