关于JAVAMAIL问题,提示说找不到SMTP服务器,可能是我的MAILSERVER错误,下面有注释,请帮忙解决,给分!
public boolean emitMail(HttpServletRequest request, String _content)
{
boolean isSucc = true;
InternetAddress[] address = null;
try
{
request.setCharacterEncoding("GB2312");
}
catch(UnsupportedEncodingException uex)
{
isSucc = false;
System.out.println("request.setCharacterEncoding(GB2312) error");
}
//这下面几句是否有错误
String mailServer = "ecd.163.com";
String from = "jb_china2008@163.com";
String to = "jb_china2004@163.com";
String title = "订报";
String content = _content;
boolean sessionDebug = false;
try
{
java.util.Properties props = System.getProperties();
props.put("mail.host", mailServer);
props.put("mail.transport.protocol", "smtp");
javax.mail.Session mailSession = javax.mail.Session.getDefaultInstance(props,
null);
mailSession.setDebug(sessionDebug);
javax.mail.Message msg = new MimeMessage(mailSession);
msg.setFrom(new InternetAddress(from));
address = InternetAddress.parse(to, false);
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject(title);
msg.setSentDate(new Date());
msg.setText(content);
Transport.send(msg);
System.out.println("邮件已顺利传送");
}
catch(MessagingException e)
{
isSucc = false;
e.printStackTrace();
}
return isSucc;
}
{
boolean isSucc = true;
InternetAddress[] address = null;
try
{
request.setCharacterEncoding("GB2312");
}
catch(UnsupportedEncodingException uex)
{
isSucc = false;
System.out.println("request.setCharacterEncoding(GB2312) error");
}
//这下面几句是否有错误
String mailServer = "ecd.163.com";
String from = "jb_china2008@163.com";
String to = "jb_china2004@163.com";
String title = "订报";
String content = _content;
boolean sessionDebug = false;
try
{
java.util.Properties props = System.getProperties();
props.put("mail.host", mailServer);
props.put("mail.transport.protocol", "smtp");
javax.mail.Session mailSession = javax.mail.Session.getDefaultInstance(props,
null);
mailSession.setDebug(sessionDebug);
javax.mail.Message msg = new MimeMessage(mailSession);
msg.setFrom(new InternetAddress(from));
address = InternetAddress.parse(to, false);
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject(title);
msg.setSentDate(new Date());
msg.setText(content);
Transport.send(msg);
System.out.println("邮件已顺利传送");
}
catch(MessagingException e)
{
isSucc = false;
e.printStackTrace();
}
return isSucc;
}
...全文
相关推荐
java socket 实现SMTP协议 发送邮件.docx
首先,我们需要创建一个 Socket 对象,并指定 SMTP 服务器的地址和端口号。然后,我们可以使用输出流来发送 SMTP 命令,并使用输入流来读取服务器的响应信息。
java-mail-server:服务器的java项目
- **异常处理**:编写健壮的代码,处理各种可能出现的错误和异常情况。- **日志记录**:实施日志记录,便于调试和监控服务器状态。
java发送邮件代码
JavaMail 的设计是基于标准的邮件协议(如 SMTP、POP3 和 IMAP),并且可以与多种不同类型的邮件服务器进行交互。
基于Java的邮件服务器
#### 四、异常处理在搭建过程中可能会遇到各种异常情况,例如配置文件错误、数据库连接失败等。需要仔细检查配置文件是否按照要求进行了正确的修改,并确保所有依赖都已正确添加。
基于socket的邮件发送程序(java编写)
虽然现代的邮件发送库如JavaMail提供了更高级的功能和错误处理,但对于学习网络编程原理和SMTP协议来说,基于Socket的实现是一个很好的起点。


