我遇到类试的问题
把邮件服务器的地址改为IP地址就能连接上了
比如说smtp.XXX.com是服务器的话
改成IP地址不要加SMTP
把邮件服务器的地址改为IP地址就能连接上了
比如说smtp.XXX.com是服务器的话
改成IP地址不要加SMTP
解决方案 »
- 关于iReport里分组之后全局统计的问题
- 请各位大侠多多指教
- mysql 的更新问题,那位大侠帮忙解决一下,非常感谢!
- 我的myeclipse-7.5.0-win32 安装报错
- 请教一个JavaScript的问题
- Java代码格式讨论
- hibernate的配置文件属性:connection.autocommit=true有哪些缺点?为何不建议使用true呢????
- 关于javamail发送邮件的问题,急急急!!!!
- 最菜的问题:如何配置tomcat
- 寻求MVC书籍或文章,入门的。有电子书最好。 谢谢
- 郁闷啊!我的第一个 EJB 还是一个 Sample 竟然出现这样莫名其妙的错误。java2iiop 是什么东西?
- SOS!,大家吃饱了喝足了,请给我一个绝对可以调用ejb的Jsp!!!
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
public class sendMail
{
public static void main(String args[]) throws Exception
{ String host = "smtp.sina.com.cn";
String from = "[email protected]";
String to = "[email protected]";
String username = "javamail";
String password = "password"; // Get system properties
// Properties props = System.getProperties(); 很多例子中是这样的,其实下面这句更好,可以用在applet中
Properties props = new Properties(); // Setup mail server
props.put("mail.smtp.host", host);
props.put("mail.smtp.auth", "true"); //这样才能通过验证 // Get session
Session session = Session.getDefaultInstance(props); // watch the mail commands go by to the mail server
session.setDebug(true); // Define message
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO,
new InternetAddress(to));
message.setSubject("Hello JavaMail");
message.setText("Welcome to JavaMail"); // Send message
message.saveChanges();
Transport transport = session.getTransport("smtp");
transport.connect(host, username, password);
transport.sendMessage(message, message.getAllRecipients());
transport.close();
}
}
import="java.util.*, javax.mail.*, javax.mail.internet.*"
errorPage="errorpage.jsp" %>
<%
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.21cn.com");
props.put("mail.smtp.auth", "true");//permit SMTP
Session s = Session.getDefaultInstance(props);
Transport transport = s.getTransport("smtp");
transport.connect( "smtp.21cn.com", "username", "******" );//
MimeMessage message = new MimeMessage(s);
InternetAddress from = new InternetAddress("[email protected]");
message.setFrom(from);
try {
String toValue = request.getParameter("to");
if(!toValue.equals("")) {
InternetAddress to = new InternetAddress(toValue);
message.addRecipient(Message.RecipientType.TO, to);
} else {
throw new MessagingException
("You must fill in a value for the \"to\" field.");
} String subject = request.getParameter("subject");
if(!subject.equals("")) {
message.setSubject(subject);
} else {
throw new MessagingException
("You must fill in a value for the \"subject\" field.");
} String text = request.getParameter("text");
if(!text.equals("")) {
MimeMultipart mm = new MimeMultipart();
MimeBodyPart mbp = new MimeBodyPart();
String type = request.getParameter("type");
mbp.setContent(text, type);
mm.addBodyPart(mbp);
message.setContent(mm);
} else {
throw new MessagingException
("You must fill in a value for the body of the message.");
}
} catch(MessagingException e) {
throw new MessagingException("Error getting form values: " +
e.toString());
}
try {
transport.send(message);
} catch(MessagingException e) {
throw new MessagingException("Cannot send mail. Please contact " +
"the <a href=\"mailto:[email protected]\">administrator</a>.");
} finally {transport.close();//
}