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

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

问题描述

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



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

  item-75@myserver.example.com 

然后,服务器将收到电子邮件并将其管道到脚本。脚本将查询数据库中的项目75以获取电子邮件地址列表,然后重新发送电子邮件。



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

解决方案

p>(这听起来像是要实现像craigslist这样的功能)。



IIS SMTP服务可以发送电子邮件,并且接受电子邮件



这是您要做的。



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



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



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



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



1)解析电子邮件。



2)相应地修改它们(你只想改变到地址吗?)。



3)如果要重新发送电子邮件,则需要相应地进行修改。
您将需要添加一个单独的X-Sender头,用于标识发送电子邮件的电子邮件地址,以及X-Receiver头,用于接收该电子邮件的每个收件人。以下是修改的电子邮件示例:

  X-Sender:me@mywebsite.com 
X-Receiver: recip1@theirdomain.com
X-Receiver:recip2@theirdomain.com
来自:jim bob< jim@example.com>
至:< item-75@myserver.example.com>
主题:test
MIME版本:1.0
内容类型:text / plain;
Message-ID:< 024f01c9e130 $ b3eca500 $ 0401a8c0 @ local>


测试

一旦你有这个修改的内容,你将其写入mailroot / pickup目录中的文件。请确保使用唯一的名称。



IIS SMTP服务将来,接收电子邮件并中继,使用X-Sender发送电子邮件MAIL FROM地址,并将其发送到每个X-Receiver头中列出的每个电子邮件地址。



4)将此脚本作为计划任务运行。另一个选择是将其构建为Windows服务,或者实现类似于filesystemwatcher的任务,每当将电子邮件创建为文件时,它将执行。



5)另一个选项所有这一切的选择是实际实现一个SMTP事件接收器,但我认为这是对你想做的事情太过分了,可以创造出更多的头痛,而不是解决这个问题。



希望我没有像泥浆一样清楚。


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

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.

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).

解决方案

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

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

Here is what you want to do.

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"

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

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)Parse the emails.

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

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

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.

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)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)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天全站免登陆