如何在 .NET/Sql Server 中以用户的本地时间发送电子邮件? [英] How to send out email at a user's local time in .NET / Sql Server?

查看:27
本文介绍了如何在 .NET/Sql Server 中以用户的本地时间发送电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个程序,需要每小时发送一封电子邮件,但在用户本地时间发送.

I am writing a program that needs to send out an email every hour on the hour, but at a time local to the user.

假设我有 2 个不同时区的用户.约翰在纽约,弗雷德在洛杉矶.服务器在芝加哥.如果我想在本地下午 6 点向每个用户发送电子邮件,我必须在服务器时间下午 7 点将电子邮件发送给 John,服务器时间下午 4 点将电子邮件发送给 Fred.

Say I have 2 users in different time zones. John is in New York and Fred is in Los Angeles. The server is in Chicago. If I want to send an email at 6 PM local to each user, I'd have to send the email to John at 7 PM Server time and Fred at 4 PM Server time.

在 .NET/Sql Server 中有什么好的方法?我找到了一个包含所有时区信息的 xml 文件,因此我正在考虑编写一个脚本将其导入数据库,然后对其进行查询.

What's a good approach to this in .NET / Sql Server? I have found an xml file with all of the time zone information, so I am considering writing a script to import it into the database, then querying off of it.

我使用了t4znet.dll"并在 .NET 端进行了所有比较.

I used "t4znet.dll" and did all comparisons on the .NET side.

推荐答案

您有两个选择:

  • 将邮件操作的调整时间存储到每个用户的数据库中.然后只需将服务器时间与存储时间进行比较.为避免混淆和便携性问题,我将所有时间都存储在 UTC 中.所以,当 SERVER_UTC_TIME() == storedUtcTime 时发送邮件.
  • 将每个邮件操作的本地时间存储到数据库中,然后即时转换.当 SERVER_UTC_TIME() == TO_UTC_TIME(storedLocalTime, userTimeZone) 时发送邮件.

您应该决定什么对您的应用程序最有意义.例如,如果所有用户的邮寄时间始终相同,则使用选项 (2) 更有意义.如果事件时间可以在用户之间甚至每个用户之间发生变化,那么如果您选择选项 (1),可能会使开发和调试更容易.无论哪种方式,您都需要知道用户的时区.

You should decide what makes most sense for your application. For example if the mailing time is always the same for all users, it makes more sense to go with option (2). If the events times can change between users and even per user, it may make development and debugging easier if you choose option (1). Either way you will need to know the user's time zone.

*这些函数调用显然是伪函数,因为我不知道它们在 T-SQL 中的调用,但它们应该存在.

*These function calls are obviously pseudo, since I don't know their invocations in T-SQL, but they should exist.

这篇关于如何在 .NET/Sql Server 中以用户的本地时间发送电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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