简体   繁体   English

处理跨多个应用程序的电子邮件分发的最佳方法是什么?

[英]What is the best way to handle email distribution across many applications?

I have many applications across an enterprise environment and they all use different methods of sending emails. 我在整个企业环境中都有许多应用程序,它们都使用不同的发送电子邮件的方法。 Some send directly through an exchange server, some queue up locally in an SMTP queue and others call aa web service that then sends the email. 有些直接通过交换服务器发送,有些在SMTP队列中本地排队,而另一些调用Web服务,然后发送电子邮件。

I'm trying to decide on the best way to get guaranteed delivery of emails. 我正在尝试确定最好的方式来确保有保证的电子邮件传递。 If our Exchange server goes down, then the applications that send to it directly can no longer send emails, also any emails sent during the down time never get anywhere. 如果我们的Exchange服务器出现故障,则直接发送到该服务器的应用程序将无法再发送电子邮件,而且在停机时间内发送的任何电子邮件也永远都收不到。 I would also like to implement a universal templating solution that all applications can share. 我还想实现所有应用程序都可以共享的通用模板解决方案。

Are there any pre-built solutions to this problem, or do you have an insight on how to handle this issue? 是否有针对此问题的预先构建的解决方案,或者您对如何处理此问题有见识?

We solved this by creating a web service that sends all our emails. 我们通过创建一个发送所有电子邮件的Web服务来解决此问题。 This web service uses the 该Web服务使用

System.Net.Mail.SmtpDeliveryMethod.PickupDirectoryFromIis 

setting, which essentially saves the files to a spot on the disk, tries to send them via the main SMTP server, and if the server is unavailable, they sit in the directory until it BECOMES available. 设置实际上将文件保存到磁盘上的某个位置,然后尝试通过主SMTP服务器发送文件,如果服务器不可用,它们将位于目录中,直到其变为可用为止。

Guaranteed delivery, as long as the web service is up. 只要Web服务启动,就可以保证交付。 Since we have redundancy checks in place, this is almost never an issue. 由于我们已经进行了冗余检查,因此这几乎绝不是问题。 If it is, we treat it as an error in code and handle it. 如果是这样,我们将其视为代码错误并进行处理。

edit - added 编辑-添加

I forgot to mention that XSS is a concern even in an email, so be sure to use something like the Microsoft.Security.AntiXss library, which contains functions like GetSafeHtmlFragment to strip out potentially dangerous scripts before outputting html to an email. 我忘了提到XSS甚至在电子邮件中也是一个问题,因此请确保使用类似Microsoft.Security.AntiXss库的东西,该库包含诸如GetSafeHtmlFragment之类的功能,以便在将html输出到电子邮件之前清除潜在的危险脚本。

http://msdn.microsoft.com/en-us/security/aa973814.aspx http://msdn.microsoft.com/en-us/security/aa973814.aspx

http://msdn.microsoft.com/en-us/library/aa973813.aspx http://msdn.microsoft.com/en-us/library/aa973813.aspx

I have heard good feedback about Postmark. 我已经收到有关Postmark的良好反馈。 Maybe a service like that could be solution as it has several integration points. 也许这样的服务可能是解决方案,因为它具有多个集成点。

http://postmarkapp.com http://postmarkapp.com

We have used HMailServer (on windows platform) which is freeware. 我们已经使用了HMailServer(在Windows平台上),它是免费软件。 Configured the max retries to too many & used external smtp to relay the emails. 将最大重试次数配置为太多,并使用外部smtp中继电子邮件。 our applications ques up emails on the HMailServer and that server relays it further. 我们的应用程序在HMailServer上查询电子邮件,然后该服务器进一步中继它。 with the max retries configured to be many if at all the main smtp servers are down we can assure that the email are delivered - but though there is no gurantee if there is huge downtime with main smtp relay servers. 如果将所有主要smtp服务器都关闭,则最大重试次数配置为很多,我们可以确保电子邮件已送达-但是,如果主要smtp中继服务器出现大量停机,则没有任何保证。

I do this by queuing email to a SQL server database. 我通过将电子邮件排队到SQL Server数据库来实现。 Any ACID compliant database will work or you can use MongoDB with 'safe mode' inserts but if you really need guaranteed then use SQL server or MySQL. 任何符合ACID的数据库都可以使用,或者您可以将MongoDB与“安全模式”插入一起使用,但是如果您确实需要保证,请使用SQL Server或MySQL。 This way if your mail gets into the database it is 'guaranteed' not to be lost and your app doesn't have to think about it. 这样,如果您的邮件进入数据库,则“保证”不会丢失,并且您的应用程序不必考虑它。 You could use a web service or just make a shared assembly with a static public method in a class to drop your email in the db for you. 您可以使用Web服务,也可以只使用类中的静态公共方法创建共享程序集,以将您的电子邮件放入数据库中。

Include a column for status like 'new', 'delivered', 'recipient mailbox temporarily full', which you can represent with numeric values and keep a TimeToSend column, which starts out as the time when the email is queued in the database. 包括一列状态,例如“新”,“已发送”,“收件人邮箱暂时已满”,您可以用数值表示它,并保留一个TimeToSend列,该列开始于电子邮件在数据库中排队的时间。

Then you have a mail app, that you can have run once a minute as a windows scheduled task. 然后,您将拥有一个邮件应用程序,该应用程序可以作为Windows计划任务每​​分钟运行一次。 Make it as a console app. 将其作为控制台应用程序。 When it loads, it checks if an instance of it already running and if there is one, it exits. 加载时,它会检查其实例是否已在运行,如果存在,则退出。 When running: 1. Attempts to deliver each mail to mail server. 运行时:1.尝试将每个邮件传递到邮件服务器。 Query the database for all mail where the TimeToSend is older than now. 在数据库中查询TimeToSend早于现在的所有邮件。
2. If mail is delivered to mail server, mark it logical deleted. 2.如果邮件已传递到邮件服务器,则将其标记为逻辑删除。 3. If any mail can't be delivered, advance the TimeToSend column for them to 10 minutes from now. 3.如果无法发送任何邮件,请从现在开始将它们的TimeToSend列提前10分钟。
4. Delete records from table that are logically deleted. 4.从表中删除逻辑删除的记录。 You can do this in the app or you can do it by having a sql job do it. 您可以在应用程序中执行此操作,也可以通过执行sql作业来执行此操作。

As mentioned earlier, you can utilize a web service that you can usually POST JSON to using an HTTP request. 如前所述,您可以利用Web服务,通​​常可以将JSON POST到使用HTTP请求。 Here are a bunch of choices: 这里有很多选择:

They all have different feature sets and offerings, so definitely give them all a spin and figure out which you prefer. 它们都有不同的功能集和产品,因此一定要给它们一个旋转,并找出您喜欢的功能。

( Full Disclosure: I am the Product Manager of PostageApp.) 完全公开:我是PostageApp的产品经理。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM