用javamail发信,提示如下错误,为什么?

cno 2003-02-26 10:16:58
我用的是sina和163的邮件服务器
smtp.sina.com.cn
163的记不清是smtp.163.com还是smtp.163.net了
反正都试了,都提示如下错误:
javax.mail.NoSuchProviderException: Invalid protocol: null
请问为什么?
...全文
226 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
myxd 2003-02-26
  • 打赏
  • 举报
回复
如果你用的TOMCAT。你可以看看tomcat代的例子。能简单
cno 2003-02-26
  • 打赏
  • 举报
回复
Properties properties = System.getProperties();
properties.put("mail.smtp.host","smtp.sina.com.cn");
properties.put("mail.transport.protocol", "smtp");
properties.put("mail.smtp.auth","true");
Session session = Session.getInstance(properties,
new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("myusername","mypassword");
}
});

try
{
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(strFrom));

InternetAddress[] toadd = InternetAddress.parse(strEmail);
message.setRecipients(Message.RecipientType.TO,toadd);

message.setSubject(strSubject);
message.setText(strFullMailText);

Transport transport = session.getTransport();
message.saveChanges();
transport.send(message,message.getAllRecipients());
transport.close();

}
catch (AddressException e)
{
System.out.println("There was an error parsing the addresses.");
System.out.println(e.getMessage());
}
catch (SendFailedException e)
{
System.out.println("There was an error sending the message.");
System.out.println(e.getMessage());
}
catch (MessagingException e)
{
System.out.println("There was an unexpected eorror.");
System.out.println(e);
}
楼上的,这是我的程序,照你的方法改了,好了
什么错误都不提示了
可就是没有收到信,见鬼了
lotofu 2003-02-26
  • 打赏
  • 举报
回复
Properties props = System.getProperties();
props.put("mail.host", host);
props.put("mail.transport.protocol", "smtp");
cno 2003-02-26
  • 打赏
  • 举报
回复
看了,是下面这些,什么意思啊?
250-sina.com
250-AUTH=LOGIN
250-AUTH LOGIN
250-PIPELINING
250 8BITMIME
250 sina.com
takecare 2003-02-26
  • 打赏
  • 举报
回复
telnet smtp.sina.com.cn 25

ehlo或helo看看该服务器支持什么样的东东
cno 2003-02-26
  • 打赏
  • 举报
回复
那怎么会出现这种情况呢?
lotofu 2003-02-26
  • 打赏
  • 举报
回复
smtp.sina.com.cn???什么意思?
协议和服务器混为一谈?!!!!!

62,615

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧