相关疑难解决方法(0)

如何使用GMail,Yahoo或Hotmail通过Java应用程序发送电子邮件?

是否可以使用GMail帐户从我的Java应用程序发送电子邮件?我已经使用Java应用程序配置我的公司邮件服务器来发送电子邮件,但是当我分发应用程序时,这不会削减它.任何使用Hotmail,Yahoo或GMail的答案都是可以接受的.

java email gmail jakarta-mail mail-server

200
推荐指数
5
解决办法
23万
查看次数

无法连接到SMTP主机:localhost,port:25; 嵌套异常是:java.net.ConnectException:连接被拒绝:连接

我正在申请从jsp发送来自localhost的电子邮件,我发现错误如无法连接到SMTP主机:localhost,port:25; 嵌套异常是:java.net.ConnectException:连接被拒绝:连接 plz检查并给我解决方案或想法,如果你有.for我正在使用下面的代码.提前感谢你.

 <%@ page language="java" import="javax.naming.*,java.io.*,javax.mail.*,
javax.mail.internet.*,com.sun.mail.smtp.*"%>

<html>
<head>
<title>Mail</title>
</head>

<body>

<%
try{
  Session mailSession = Session.getInstance(System.getProperties());

  Transport transport = new SMTPTransport(mailSession,new URLName("localhost"));

  transport.connect("localhost",25,null,null);


  MimeMessage m = new MimeMessage(mailSession);

  m.setFrom(new InternetAddress(%><%request.getParameter("from")%><%));

  Address[] toAddr = new InternetAddress[] {
              new InternetAddress(%><%request.getParameter("to")%><%)
            };
  m.setRecipients(javax.mail.Message.RecipientType.TO, toAddr );

  m.setSubject(%><%request.getParameter("subject")%><%);

  m.setSentDate(new java.util.Date());

  m.setContent(%><%request.getParameter("description")%><%, "text/plain");

  transport.sendMessage(m,m.getAllRecipients());

  transport.close();

  out.println("Thanks for sending mail!");
}
catch(Exception e){

  out.println(e.getMessage());
  e.printStackTrace();
}
%>


</body>

</html>
Run Code Online (Sandbox Code Playgroud)

email jsp

8
推荐指数
1
解决办法
14万
查看次数

标签 统计

email ×2

gmail ×1

jakarta-mail ×1

java ×1

jsp ×1

mail-server ×1