SMTP使用外部服务器发送/接收

时间:2022-10-25 18:14:44

I've created a php script that works in the following way:

我创建了一个php脚本,它以下列方式工作:

  1. New product received from billing in form of email
  2. 通过电子邮件形式从结算中收到新产品

  3. Current localhost smtp server receives the email and is configured to use ~/mail/new/ folder to put each email as a file
  4. 当前localhost smtp服务器接收电子邮件并配置为使用〜/ mail / new /文件夹将每封电子邮件作为文件放入

  5. script reads the folder, parses each email file and then creates a project to track turn up
  6. 脚本读取文件夹,解析每个电子邮件文件,然后创建一个项目来跟踪开始

Complication: IT department wants me to use our internal MS Exchange server instead of the smtp server on the host to assist with spam issues.

复杂性:IT部门希望我使用内部MS Exchange服务器而不是主机上的smtp服务器来协助解决垃圾邮件问题。

So basically I need to either figure out 1 of 2 things. Easiest thing I can think of is configuring postfix to send/receive mail using the Exchange SMTP server, however I've only been able to find guides on how to send mail through a relayhost, not receive. I also found ssmtp, but again it's send only. I thought of using ssmtp to send and setting up some kind of cron every 10 minutes to check for received emails.

所以基本上我需要弄清楚两件事中的一件。我能想到的最简单的事情是配置postfix以使用Exchange SMTP服务器发送/接收邮件,但是我只能找到有关如何通过中继主机发送邮件而不是接收邮件的指南。我也找到了ssmtp,但它只是发送了。我想过用ssmtp每隔10分钟发送和设置一些cron来检查收到的电子邮件。

Second option is hard coding the SMTP details into the php script, which I am opposed to doing.

第二个选项是将SMTP详细信息硬编码到php脚本中,我反对这样做。

I'm open to suggestions. Server is Centos 7 x64.

我愿意接受建议。服务器是Centos 7 x64。

2 个解决方案

#1


0  

If the incoming messages are received by an exchange server, then you should be able to use PHP's built-in IMAP functions to fetch the messages from the mailbox on the exchange server. See http://php.net/manual/en/book.imap.php.

如果传入消息是由交换服务器接收的,那么您应该能够使用PHP的内置IMAP函数从Exchange服务器上的邮箱中获取消息。见http://php.net/manual/en/book.imap.php。

#2


0  

I ended up using fetchmail + postfix to do this.

我最终使用fetchmail + postfix来做到这一点。

installed fetchmail

sudo yum install fetchmail

I had several users that were servicing different scripts, so I had to create ~/.fetchmailrc for each user with the following format:

我有几个服务于不同脚本的用户,因此我必须为每个用户创建〜/ .fetchmailrc,格式如下:

poll imap.server.com proto imap:
        user "imapusername" is localusername here
        with password "password"
        folder "Custom Folder"
        keep
        ssl
        fetchall

Then, in each user's crontab, I put an entry to run fetchmail every ten minutes:

然后,在每个用户的crontab中,我每十分钟放一个条目来运行fetchmail:

*/10 * * * * fetchmail

As for sending, I kept the solution of configuring postfix to use the imap server as relay host:

至于发送,我保留了配置postfix的解决方案,使用imap服务器作为中继主机:

relayhost = [imap.server.com]

Our exchange server is configured to not relay mail from internal hosts to the mail spam gateway. IT is happy, scripts work.

我们的Exchange服务器配置为不将邮件从内部主机中继到邮件垃圾邮件网关。 IT很开心,脚本也很有用。

#1


0  

If the incoming messages are received by an exchange server, then you should be able to use PHP's built-in IMAP functions to fetch the messages from the mailbox on the exchange server. See http://php.net/manual/en/book.imap.php.

如果传入消息是由交换服务器接收的,那么您应该能够使用PHP的内置IMAP函数从Exchange服务器上的邮箱中获取消息。见http://php.net/manual/en/book.imap.php。

#2


0  

I ended up using fetchmail + postfix to do this.

我最终使用fetchmail + postfix来做到这一点。

installed fetchmail

sudo yum install fetchmail

I had several users that were servicing different scripts, so I had to create ~/.fetchmailrc for each user with the following format:

我有几个服务于不同脚本的用户,因此我必须为每个用户创建〜/ .fetchmailrc,格式如下:

poll imap.server.com proto imap:
        user "imapusername" is localusername here
        with password "password"
        folder "Custom Folder"
        keep
        ssl
        fetchall

Then, in each user's crontab, I put an entry to run fetchmail every ten minutes:

然后,在每个用户的crontab中,我每十分钟放一个条目来运行fetchmail:

*/10 * * * * fetchmail

As for sending, I kept the solution of configuring postfix to use the imap server as relay host:

至于发送,我保留了配置postfix的解决方案,使用imap服务器作为中继主机:

relayhost = [imap.server.com]

Our exchange server is configured to not relay mail from internal hosts to the mail spam gateway. IT is happy, scripts work.

我们的Exchange服务器配置为不将邮件从内部主机中继到邮件垃圾邮件网关。 IT很开心,脚本也很有用。