入力されたデータが正しいかどうかを確認し、それをデータベースに追加して電子メールを送信する必要があるアプリケーションのボタンがあります。これは次のコードで表されます。
<%@ page import = "java.text.*" %>
<%@ page import="java.io.*,java.util.*,javax.mail.*, javax.mail.Service"%>
<%@ page import="javax.mail.internet.*,javax.activation.*"%>
<%@ page import="javax.servlet.http.*,javax.servlet.*" %>
[...]
<a href="javascript:void();" onclick="
javascript:if(confirmaEnviar())$('#usuario').submit();
<% String result;
// Recipient's email ID needs to be mentioned.
String host = "smtp.gmail.com";
String to = "existingdirection@gmail.com";
String from = "existingdirection2@gmail.com";
String subject = "test";
String messageText = "body test";
Properties props = System.getProperties();
props.put("mail.host", host);
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.port", "25");
// If using authentication, otherwise comment out
props.put("mail.smtp.auth", "true");
// Gmail requires TLS, your server may not
props.put("mail.smtp.starttls.enable", "true");
Session mailSession = Session.getDefaultInstance(props, null);
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 Date());
msg.setText(messageText);
Transport transport = mailSession.getTransport("smtp");
//connect with authentication
transport.connect(host,"existingdirection2@gmail.com" , "password");
transport.sendMessage(msg, address);
transport.close();
%>
return false;" class="button button-alt">ENVIAR</a></div>
しかし、アップロードして実行しようとすると、ブラウザーにエラーが表示されます: エラー: サーバー エラー サーバーでエラーが発生し、要求を完了できませんでした。
jspコードをそのように(onclickの途中で)呼び出すことができないのではないかと考えていましたが、コードの別の場所(htmlタグの途中)に配置すると、エラーが再現されます。
Java メールのライブラリを Java ビルド パスに追加し、それを lib ディレクトリにもコピーしました。
もちろん、失敗したのは電子メール関連のコードであることがテストされています。アプリケーションから削除すると、残りはうまくいきます。
パスワードの電子メールの指示も正しいことが確認されています。
アプリケーションをホストするために GAE を使用しています。
何が起こっているのでしょうか?
あなたの助けに感謝します。
編集:それはスタックトレースです。結局のところ、コード関連の質問ではないと思います..
com.google.apphosting.api.ApiProxy$FeatureNotEnabledException: 管理コンソールで課金が有効になると、このアプリケーションに対してソケット API が有効になります。java.lang.Thread.getStackTrace(Thread.java:1567) で com.google.apphosting.runtime.ApiProxyImpl.doSyncCall(ApiProxyImpl.java:259) で com.google.apphosting.runtime.ApiProxyImpl.access$000(ApiProxyImpl. java:68) com.google.apphosting.runtime.ApiProxyImpl$1.run(ApiProxyImpl.java:202) で com.google.apphosting.runtime.ApiProxyImpl$1.run(ApiProxyImpl.java:199) で java.security.AccessController com.google.apphosting.runtime.ApiProxyImpl.makeSyncCall(ApiProxyImpl.java:199) の .doPrivileged(ネイティブ メソッド) com.google.apphosting.runtime.ApiProxyImpl.makeSyncCall(ApiProxyImpl.java:68) の com.google.apphosting .api.ApiProxy.makeSyncCall(ApiProxy.java:107) com.google.apphosting.api で。
困ったことに、Google Api のコンソールには Socket API という API がありません。Google のコンサルタントにも問い合わせてみようと思います。