0

これは私の送信メールのコードです

<html>
 <head>
<title>JSP JavaMail Example </title>
 </head>

<body>

<%@ page import="java.util.*" %>
<%@ page import="javax.mail.*" %>
<%@ page import="javax.mail.internet.*" %>
<%@ page import="javax.activation.*" %>
<%@ page import="javax.mail.Authenticator" %>
<%@ page import="javax.mail.PasswordAuthentication" %>
<%@ page import="java.sql.*" %>
<%@ page import="com.google.appengine.api.rdbms.*" %>
<%@ page import="com.sun.mail.smtp.*" %>
<%@ page import="com.google.appengine.api.mail.*" %>

<%

class GMailAuthenticator extends Authenticator {
 String user;
 String pw;
 public GMailAuthenticator (String username, String password)
 {
    super();
    this.user = username;
    this.pw = password;
 }
public PasswordAuthentication getPasswordAuthentication()
{
   return new PasswordAuthentication(user, pw);
}
}

String host = "smtp.gmail.com";
String user= "rxxxxxxxxxxx@gmail.com";
String pass= "xxxxxxxxx";
String to = request.getParameter("to");
String from = request.getParameter("from");
String subject = request.getParameter("subject");
String messageText = request.getParameter("body");
boolean sessionDebug = false;

String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";

Properties props = System.getProperties();
props.put("mail.host", host);
props.put("mail.smtp.", "true");
props.put("mail.smtp.port", "465");
props.put("mail.smtp.socketFactory.fallback", "true");
props.put("mail.smtp.socketFactory.class", SSL_FACTORY); 
props.put("mail.debug", "true"); 
props.put("mail.smtp.auth", "true");
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.starttls.enable",true);
props.put("mail.smtp.starttls.required",true);

Session mailSession =Session.getInstance(props, new GMailAuthenticator(user, pass));

mailSession.setDebug(sessionDebug);

Message msg = new MimeMessage(mailSession);

msg.setFrom(new InternetAddress(from));
InternetAddress[] address = {new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject(subject);
msg.setSentDate(new java.util.Date());
msg.setText(messageText);

Transport transport = mailSession.getTransport("smtp");
transport.connect(host,user,pass);

Transport.send(msg);

out.println("Mail was sent to " + to);
out.println(" from " + from);
out.println(" using host " + host + ".");
response.sendRedirect("verify.jsp");

String u= String.valueOf(session.getAttribute("un"));

Connection c = null;
PreparedStatement ps=null;
ResultSet rs=null;
Class.forName("com.mysql.jdbc.Driver");
DriverManager.registerDriver(new AppEngineDriver());
c =     DriverManager.getConnection("jdbc:google:rdbms://ctsteaching:ctsdatabase/ctsdb");


String query="update Registration set Status='Active' where Username=? ";
ps=c.prepareStatement(query);
ps.setString(1,u.trim());
ps.executeUpdate();

   %>
   </table>
  </body>
 </html>

クラウドにデプロイした後、メールの送信中に次のエラーが発生します。

java.lang.NoClassDefFoundError: javax.net.SocketFactory is a restricted class. Please see the Google App Engine developer's guide for more details.
    at com.google.appengine.runtime.Request.process-02f037dc0f1c0aab(Request.java)
    at javax.net.SocketFactory.<clinit>(SocketFactory.java)
    at java.lang.reflect.Method.invoke(Method.java:43)
    at com.sun.mail.util.SocketFetcher.getSocketFactory(SocketFetcher.java:382)
    at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:193)
    at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1938)
    at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:642)
    at javax.mail.Service.connect(Service.java:248)
    at javax.mail.Service.connect(Service.java:91)
    at org.apache.jsp.sendMail_jsp._jspService(sendMail_jsp.java:118)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
    at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
    at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at org.mortbay.jetty.Server.handle(Server.java:326)
    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
    at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
    at com.google.tracing.TraceContext$TraceContextRunnable.runInContext(TraceContext.java:449)
    at com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:455)
    at com.google.tracing.TraceContext.runInContext(TraceContext.java:695)
    at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:333)
    at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:325)
    at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:453)
    at java.lang.Thread.run(Thread.java:679)
4

3 に答える 3

3

javax.net.SocketFactory は AE のホワイトリストにないため、使用できません。 https://developers.google.com/appengine/docs/java/jrewhitelist

メールを送信するには、 https://developers.google.com/appengine/docs/java/mail/usingjavamailを参照してください。

于 2012-07-03T08:34:42.027 に答える
0

APP Engine API を使用する必要があります。

以下のサイトで例を見つけることができます..

http://programcreek.com/java-api-examples/index.php?api=com.google.appengine.api.mail.MailServiceFactory

于 2014-09-27T15:18:10.093 に答える
0

AppEngine で制限されている SMTP サーバーへのソケットを開くため、Java メールを使用して電子メールを送信することはできません。AppEngine メール APIまたはサードパーティの http ベースのメール API (Amazon や Mailchimp など)
を使用する必要があります。

于 2012-07-03T08:34:02.427 に答える