0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

RedmineからOffice365へのメール送信

Last updated at Posted at 2023-05-19

内容

 EC2からDockerで立ち上げたredmineで、OFFICE365へのmail送信が出来ず、ついにpythonでリレーメールすることで解決した。

完成コード

 一応、自宅のNASでは動作した。月曜に会社の環境で再テストする。
 なぜRedmineから送れなかったのかは、原因不明のままであるが・・・

注意点

  • NASはIPアドレスとすること(ホスト名では送れず)
  • 1025はポート開放すること
  • dockerホストのアドレスでは送信不可(localhost)
python.py
import smtpd
import asyncore
import smtplib
import pdb

class CustomSMTPServer(smtpd.SMTPServer):
    def process_message(self, peer, mailfrom, rcpttos, data, **kwargs):
        # Forward the message to another SMTP server
        smtpObj = smtplib.SMTP('smtp.office365.com', 587)
        smtpObj.starttls()
        smtpObj.login("アドレス","パスワード")
        smtpObj.sendmail("送信元", "宛先", data)

server = CustomSMTPServer(('192.168.1.40', 1025), None)
asyncore.loop()
configuration.yml
default:
  # Outgoing emails configuration
  # See the examples below and the Rails guide for more configuration options:
  # http://guides.rubyonrails.org/action_mailer_basics.html#action-mailer-configuration
  email_delivery:
  # ==== Simple SMTP server at localhost
    delivery_method: :smtp
    smtp_settings:
      address: "192.168.1.40"
      port: 1025

はまったこと

・Redmineだけで解決しようとしていたが、問題はメールサーバー側であった。
・ドッカー環境、EC2クラウド環境、さんざん突き詰めて丸3日悩む。
・メールサーバーも、ポート開放やなんやらで悩み倒す。
・最後が自前と言うのは自分のアイデアで解決 → CHATGPTはひらめきは与えてくれないが、アイデアを具現化するには役立った。

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?