java发邮件新浪_JavaMail如何通过sina企业邮箱进行发送邮件?

JavaMail如何通过sina企业邮箱进行发送邮件? 通过sina的免费邮箱完全可以正常发送,不知道为什么,谁可以帮我下!万分感谢!

下面是我的代码:

smtpAuth.getuserinfo("email@mlee.com.cn", "******");

Properties props = System.getProperties();

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

props.put("mail.smtp.host", "smtp.sina.com.cn");

Session session = Session.getInstance(props, smtpAuth);

Message msg = new MimeMessage(session);

msg.setDataHandler(new DataHandler(body,"text/html; charset=gb2312"));

msg.setFrom(new InternetAddress("email@mlee.com.cn","yangqr"));

msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to,

false));

Transport t = session.getTransport("smtp");

t.connect("smtp.sina.com.cn", "email@mlee.com.cn", "******");

msg.setSubject(MimeUtility.encodeText(subject, "gb2312", "b"));

msg.setSentDate(new Date());

msg.setContent(body, "text/html; charset=GBK");

Transport.send(msg);

以下是控制台输出的信息:

DEBUG: setDebug: JavaMail version 1.3.1

DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]

DEBUG SMTP: useEhlo true, useAuth true

DEBUG SMTP: trying to connect to host "smtp.sina.com.cn", port 25

220 mail5-203.sinamail.sina.com.cn ESMTP

DEBUG SMTP: connected to host "smtp.sina.com.cn", port: 25

EHLO yangqing-132788

250-mail5-203.sinamail.sina.com.cn

250-8BITMIME

250-SIZE 31457280

250-AUTH PLAIN LOGIN

250 AUTH=PLAIN LOGIN

DEBUG SMTP: Found extension "8BITMIME", arg ""

DEBUG SMTP: Found extension "SIZE", arg "31457280"

DEBUG SMTP: Found extension "AUTH", arg "PLAIN LOGIN"

DEBUG SMTP: Found extension "AUTH=PLAIN", arg "LOGIN"

DEBUG SMTP: Attempt to authenticate

AUTH LOGIN

334 VXNlcm5hbWU6

ZW1haWxAbWxlZS5jb20uY24=

334 UGFzc3dvcmQ6

MTIzNDU2

535 #5.7.0 Authentication failed

DEBUG SMTP: useEhlo true, useAuth true

DEBUG SMTP: trying to connect to host "smtp.sina.com.cn", port 25

220 mail5-201.sinamail.sina.com.cn ESMTP

DEBUG SMTP: connected to host "smtp.sina.com.cn", port: 25

EHLO yangqing-132788

250-mail5-201.sinamail.sina.com.cn

250-8BITMIME

250-SIZE 31457280

250-AUTH PLAIN LOGIN

250 AUTH=PLAIN LOGIN

DEBUG SMTP: Found extension "8BITMIME", arg ""

DEBUG SMTP: Found extension "SIZE", arg "31457280"

DEBUG SMTP: Found extension "AUTH", arg "PLAIN LOGIN"

DEBUG SMTP: Found extension "AUTH=PLAIN", arg "LOGIN"

DEBUG SMTP: Attempt to authenticate

AUTH LOGIN

334 VXNlcm5hbWU6

ZW1haWxAbWxlZS5jb20uY24=

334 UGFzc3dvcmQ6

MTIzNDU2

535 #5.7.0 Authentication failed

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,关于使用JavaMail发送和读取邮件的问题,我可以给你一些简单的介绍。 首先,你需要导入JavaMail的jar包,然后创建Session对象,设置邮件服务器的配置信息和账号授权信息。例如: ```java Properties props = new Properties(); props.setProperty("mail.smtp.host", "smtp.example.com"); props.setProperty("mail.smtp.auth", "true"); Session session = Session.getDefaultInstance(props, new Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication("your_username", "your_password"); } }); ``` 然后,你可以使用Message对象来创建邮件内容,并使用Transport对象将邮件发送出去。例如: ```java Message message = new MimeMessage(session); message.setFrom(new InternetAddress("sender@example.com")); message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("recipient@example.com")); message.setSubject("Testing JavaMail"); message.setText("Hello World!"); Transport.send(message); ``` 如果你需要读取邮件,也可以使用JavaMail提供的API。你需要连接到邮件服务器,打开收件箱,并遍历所有邮件。例如: ```java Store store = session.getStore("pop3"); store.connect("pop3.example.com", "your_username", "your_password"); Folder inbox = store.getFolder("INBOX"); inbox.open(Folder.READ_ONLY); Message[] messages = inbox.getMessages(); for (int i = 0; i < messages.length; i++) { Message message = messages[i]; System.out.println("Subject: " + message.getSubject()); } inbox.close(false); store.close(); ``` 这只是JavaMail的简单使用方式,如果你需要更多的功能,可以参考JavaMail的官方文档或者其他相关的教程。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值