其次,9楼的兄弟,JavaMail是一个写好了的mail发送的包,免费的,使用方便!
你真的会OOP了?真的明白了?10楼的姐妹?我准备发一个帖子,大家可以过来看看,自称会OOP的朋友来答答几个问题!
别做程序了,给你们一个赚钱的秘诀。做豆腐;if 做硬了 then 卖豆腐干;if 做稀了 then 卖豆腐花;if 太稀了 then 卖豆浆;if 豆腐卖不动了放几天 then 卖臭豆腐; else if 还卖不动放坏了 then 卖腐乳;
哎试着连接了好几次都没有成功都是下面的Exception:
javax.mail.MessagingException: Could not connect to SMTP host: 66.94.234.13, port: 25; nested exception is: java.net.ConnectException: Connection timed out: connect
我的HTML如下:
<html>
<BODY>
<FORM action="sendmail.jsp" method="post">
<TABLE align="center">
<TR>
<TD width="50%">
<p>收件人:</p><BR><INPUT name="to" size="25">
</TD>
<TD width="50%">
<p>寄信人:</p><BR><INPUT name="from" size="25">
</TD>
</TR>
<TR>
<TD colspan="2">
<p>主题:</p><BR><INPUT name="subject" size="50">
</TD>
</TR>
<TR>
<TD colspan="2">
<p>邮件正文:<BR><TEXTAREA name="text" rows=25 cols=85></TEXTAREA></p>
</TD>
</TR>
</TABLE>
<INPUT type="submit" name="cb_submit" value="发送">
<INPUT type="reset" name="cb_reset" value="重写">
</FORM>
</BODY>
</HTML>
我的JSP sendmail.jsp
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import=" javax.mail.*, javax.mail.internet.*, javax.activation.*,java.util.*" %>
<html>
<head>
<TITLE>JavaMail 电子邮件发送系统</TITLE>
</HEAD>
<BODY>
<%
try{
Properties props = new Properties();
Session sendMailSession;
Store store;
Transport transport;
sendMailSession = Session.getInstance(props, null);
props.put("mail.smtp.host", "66.94.234.13");//yahoo.com的IP
Message newMessage = new MimeMessage(sendMailSession);
newMessage.setFrom(new InternetAddress(request.getParameter("from")));
newMessage.setRecipient(Message.RecipientType.TO, new InternetAddress(request.getParameter("to")));
newMessage.setSubject(request.getParameter("subject"));
newMessage.setSentDate(new Date());
newMessage.setText(request.getParameter("text"));
transport = sendMailSession.getTransport("smtp");
transport.send(newMessage);
%>
<p>你的邮件已发送,请返回。</p>
<%
}
catch(MessagingException m)
{
out.println(m.toString());
}
%>
</BODY>
</HTML>