将传入的电子邮件通过管道传输到 Windows IIS SMTP 上的脚本? [英] Pipe incoming email to a script on Windows IIS SMTP?

查看:12
本文介绍了将传入的电子邮件通过管道传输到 Windows IIS SMTP 上的脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在 Windows IIS 上运行的 Web 应用程序.这个应用程序有一个数据库,其中每个项目都有一个唯一的键(1、2、3...)和一个电子邮件地址列表(除其他外).

I have a web application running on Windows IIS. This app has a database where each item has a unique key (1, 2, 3...), and a list of email addresses (among other things).

我希望用户使用标识项目的电子邮件地址向服务器发送电子邮件,然后让服务器将消息中继到该项目的电子邮件地址.例如,如果用户向以下地址发送电子邮件:

I would like users to send email to the server, using an email address that identifies the item, then have the server relay the message to the email addresses for that item. For example, if a user sends email to the following address:

item-75@myserver.example.com

然后服务器将接收电子邮件并将其通过管道传输到脚本.该脚本将在数据库中查询项目 75 以获取电子邮件地址列表,然后重新发送电子邮件.

Then the server would receive the email and pipe it to a script. The script would query the database for item 75 to get a list of email addresses, then re-send the email.

我可以在 unix 系统上使用 sendmail 轻松完成此操作,但我不知道是否可以在 Windows 系统上完成类似的设置(或者是否需要额外的软件).

I could do this easily on a unix system using sendmail, but I have no idea if a similar setup can be accomplished on a Windows system (or if it would require additional software).

推荐答案

(这听起来像是你想实现一个像 craigslist 这样的功能).

(This sounds like you want to implement a feature like craigslist).

IIS SMTP 服务可以发送邮件,也可以接受邮件.

The IIS SMTP service can send email, and also accept email.

这就是你想要做的.

配置您的 IIS SMTP 服务以接受域的电子邮件(您可以在域下的 IIS SMTP 服务的属性中进行配置).说出域名myserver.example.com"

Configure your IIS SMTP service to accept emails for a domain (You can configure this in the properties of the IIS SMTP service, under domains). Say domain name "myserver.example.com"

然后,在您的 DNS 服务器中,配置指向myserver.example.com"的 MX 记录.

Then, in your DNS server, configure a MX record that points to "myserver.example.com".

现在,当电子邮件被发送到您的 IIS SMTP 服务器时,它实际上会被放置在您的 mailroot/drop 文件夹中(您也可以在 IIS SMTP 服务属性中更改此文件夹).

Now, when email gets sent to your IIS SMTP server, it will actually get placed in your mailroot/drop folder (you can also change this folder in the IIS SMTP Service properties).

现在您正在接受电子邮件,下一步是编写一个脚本:

Now that you are accepting email, the next step is to write a script that will:

1)解析邮件.

2) 相应地修改它们(您只是想更改to"地址吗?).

2)Modify them accordingly (do you just want to change the "to" address?).

3)如果你想重新发送邮件,那么你需要相应地修改它们.您将需要添加一个 X-Sender 标头,用于标识发送电子邮件的电子邮件地址,以及一个 X-Receiver 标头,用于每个将接受电子邮件的收件人.以下是修改后的示例电子邮件:

3)If you want to resend the emails, then you need to modify them accordingly. You will need to add a single X-Sender header, that is used to identify the email address sending the email, and a X-Receiver header, for each recipient that is going to accept the email. Here is an example email that was modified:

X-Sender: me@mywebsite.com
X-Receiver: recip1@theirdomain.com
X-Receiver: recip2@theirdomain.com
From: "jim bob" <jim@example.com>
To: <item-75@myserver.example.com>
Subject: test
MIME-Version: 1.0
Content-Type: text/plain;
Message-ID: <024f01c9e130$b3eca500$0401a8c0@local>


test

一旦你有了这个修改过的内容,你就会想把它写到 mailroot/pickup 目录中的一个文件中.请务必使用唯一的名称.

Once you have this modified content, you will want to write it to a file in the mailroot/pickup directory. Be sure to use a unique name.

IIS SMTP 服务将过来,提取电子邮件,并将其转发,使用 X-Sender 作为 MAIL FROM 地址发送电子邮件,并将其发送到每个 X-Receiver 标头中列出的每个电子邮件地址.

The IIS SMTP Service will come by, pickup the email, and relay it on, sending the email using the X-Sender as the MAIL FROM address, and sending it to each email address listed in each X-Receiver header.

4)将此脚本作为计划任务运行.另一种选择是将其构建为 Windows 服务,或实现类似文件系统观察器的功能,每次将电子邮件创建为文件时都会在其中执行.

4)Run this script as a scheduled task. Another option is to build it as a windows service, or to implement something like a filesystemwatcher, where it executes each time an email is created as a file.

5)所有这一切的另一个选择是实际实现一个 SMTP 事件接收器,但我认为这对于你想要做的事情来说太过分了,而且会带来更多的麻烦,而不是它所解决的问题.如果我喜欢痛苦,我只会走事件接收器路线.

5)Another option to all of this is to actually implement a SMTP Event Sink, but I think that is overkill for what you want to do, and can create more headaches, than it solves. I would only go the event sink route if I like pain.

希望我没有把它弄得像泥巴一样清晰.

Hopefully I didn't make that about as clear as mud.

这篇关于将传入的电子邮件通过管道传输到 Windows IIS SMTP 上的脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆