他の人が言及しているように、ファイアウォールは SMTP の問題です。それでも、独自のインフラストラクチャや「隠し」パスワードをホストせずに、メールを配信する簡単な方法があります。gmail などの無料のメール アカウントを登録して、このアドレスに直接メールを送信するだけです。Gmail の SMTP サーバーをリレーとして使用していないため、ユーザー名とパスワードは必要ありません。
public static String[] lookupMailHosts(final String domainName) throws NamingException {
final InitialDirContext iDirC = new InitialDirContext();
final Attributes attributes = iDirC
.getAttributes("dns:/" + domainName, new String[] { "MX" });
final Attribute attributeMX = attributes.get("MX");
if (attributeMX == null) {
return new String[] { domainName };
}
final String[][] pvhn = new String[attributeMX.size()][2];
for (int i = 0; i < attributeMX.size(); i++) {
pvhn[i] = ("" + attributeMX.get(i)).split("\\s+");
}
// sort the MX RRs by RR value (lower is preferred)
Arrays.sort(pvhn, new Comparator<String[]>() {
public int compare(final String[] o1, final String[] o2) {
return Integer.parseInt(o1[0]) - Integer.parseInt(o2[0]);
}
});
// put sorted host names in an array, get rid of any trailing '.'
final String[] sortedHostNames = new String[pvhn.length];
for (int i = 0; i < pvhn.length; i++) {
sortedHostNames[i] = pvhn[i][1].endsWith(".") ? pvhn[i][1].substring(0, pvhn[i][1]
.length() - 1) : pvhn[i][1];
}
return sortedHostNames;
}
例えば:
public static void main(String[] args) throws Exception {
// prints [gmail-smtp-in.l.google.com, alt1.gmail-smtp-in.l.google.com, alt2.gmail-smtp-in.l.google.com, alt3.gmail-smtp-in.l.google.com, alt4.gmail-smtp-in.l.google.com]
System.out.println(Arrays.asList(lookupMailHosts("gmail.com")));
}
したがって、javax.mail の最初の選択肢として「gmail-smtp-in.l.google.com」を使用します。
Properties props = new Properties();
props.setProperty("mail.smtp.host", lookupMailHosts("gmail.com")[0]);
// ... other properies
Session smtpSession = Session.getInstance(props, null)
このアプローチを、AppEngine でホストされる単純な HTTP から SMTP への種類のサービスと組み合わせることもできます。HTTP POST リクエストを受信し、上記の方法を使用して電子メールとして転送するだけです。