ラベル smtp-auth の投稿を表示しています。 すべての投稿を表示
ラベル smtp-auth の投稿を表示しています。 すべての投稿を表示

2014年10月8日水曜日

JavaMailでsmtp-authでメールを送信する方法

    Properties props = new Properties();
    props.put("mail.transport.protocol", "smtp");  <----25か587のサブミッションポートでもok
    props.put("mail.smtp.host", SMTP_HOST_NAME);
    props.put("mail.smtp.auth", "true")

    Authenticator auth = new SMTPAuthenticator();
    Session mailSession = Session.getDefaultInstance(props, auth);

    // パスワード認証のプライベートクラス
    private class SMTPAuthenticator extends javax.mail.Authenticator {  
        public PasswordAuthentication getPasswordAuthentication() {
           String username = SMTP_AUTH_USER;
           String password = SMTP_AUTH_PWD;
           return new PasswordAuthentication(username, password);
        }
    }


http://www.rgagnon.com/javadetails/java-0538.html

2014年10月4日土曜日

Postfixで587のサブミッションポートでsmtp-auth設定をした上で、25ポートでのsmtp-authをさせないように設定するには。

Postfixで587のサブミッションポートでsmtp-auth設定をした上で、25ポートでのsmtp-authをさせないように設定するには、/etc/postfix/master.cfを以下のように編集。

smtp      inet  n       -       -       -       -       smtpd

  -o smtpd_sasl_auth_enable=no  <---------- ここをno

submission inet n       -       -       -       -       smtpd
  -o smtpd_sasl_auth_enable=yes       <---------- ここをyes

参考リンク:

2014年10月3日金曜日

Postfixでsaslauthdにハマった。。。のでメモ。

UbuntuのPostfixでsmtp-auth認証を設定する時に一番ハマったのがsaslauthdの設定。結論からすると設定ファイルのミスという単純なものだったのだが、結構ハマったのでメモ。

/etc/default/saslauthdの中身

# Should saslauthd run automatically on startup? (default: no)

START=yes <-------ここをyesにするのだが、大文字のYESにしてしまうとsaslauthdは起動しない。

起動時のエラーメッセージで気付くべきだったのだが、、、、ハマってしまった。

チェックポイント:
/var/log/mail.log
/usr/sbin/testsaslauthd -u username -p password



参考リンク
https://forums.ubuntulinux.jp/viewtopic.php?id=6750



Postfixのsmtp-auth設定でRelay Access Denied 554エラーが出る

UbuntuでPostfixのsmtp-auth設定でRelay Access Denied 554エラーが出た場合の対処法。

/etc/postfix/main.cf


smtpd_relay_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination

ポイントはpermit_sasl_authenticatedをreject_unauth_destinationの前に追加してやること。これがないとsmtp-authでのリレーアクセスができない。

参考リンク
http://askubuntu.com/questions/390401/relay-access-denied-error-554

telnetでsmtp-authの動作確認方法

telnetでsmtp-authの動作確認をしたかったのでメモ。クライアントサイドの入力のみでサーバー側の応答は省く。

% telnet mail.test.com 25

% helo mail.test.com

% auth login      <----------- SMTP-AUTHをすることを伝える。

% xxxxxxxx      <----------- base64エンコードされたユーザアカウント。

% xxxxxxxx      <----------- base64エンコードされたパスワード。

% mail from: <sender@abc.com>

% rcpt to: <reciver@efg.com>

% data
% Subject: abcded
% abcdefg
%
% This is a test message....
% .     <---------- ピリオドで終える。

% quit


ハマったとこはbase64エンコードされたID/PASSの設定。どうもパスワードに特殊記号が含まれているとbase64が失敗しているのか、認証に失敗してしまっていた。ここは精製方法を要調査。

参考リンク
http://www.anta.net/misc/telnet-troubleshooting/smtp.shtml
https://www.ndchost.com//wiki/doku.php?id=mail/test-smtp-auth-telnet
http://vogel.at.webry.info/201308/article_1.html