我正在将ASP.NET MVC 5与Microsoft SQL Server 2012一起使用。在我的应用程序中,供应商可以在线提交报价。现在,系统要求是,一旦到达报价截止日期(和时间),例如2016年11月18日(星期五)下午5:00,系统应向采购经理发送一封自动电子邮件,详细列出所有提交者的清单。与他们的价格。
有人可以解释一下如何发送自动电子邮件。我已经完成了在线搜索,有人说要使用Windows Service或Quartz.Net或SQL Server代理,但是我不确定该怎么做。
作为参考,以下是我的Quotation类,并且表字段与类属性完全相同。我有一个名为“ EndDate”的字段,用于存储报价结束日期和时间:
public partial class tblQuotationRequest
{
public System.Guid QuotationRequestId { get; set; }
public string QuotationReferenceNum { get; set; }
public string Campus { get; set; }
public string Department { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public System.DateTime StartDate { get; set; }
public System.DateTime EndDate { get; set; }
public Nullable<short> QuotationStatusID { get; set; }
public string CreatedBy { get; set; }
public Nullable<System.DateTime> CreatedDate { get; set; }
public string ModifiedBy { get; set; }
public Nullable<System.DateTime> ModifiedDate { get; set; }
}
与同事联系后,我在Microsoft SQL Server中创建了一个计划作业,该作业运行存储过程,如下所示。存储过程所做的是检查并拉出当天关闭的所有报价。如果有,它将格式化电子邮件的正文内容并将其存储在变量@tableHTML中。
然后,它将使用提供相关参数的msdb.dbo.sp_send_dbmail命令发送电子邮件。请注意,您将需要在SQL Server上配置电子邮件发送配置文件。这可以使用数据库邮件配置向导来完成。
希望这可以帮助。
CREATE PROC [dbo].[p_QUOTATION_CLOSE_SUMMARY]
AS
SET NOCOUNT ON
SET XACT_ABORT ON
BEGIN TRAN
DECLARE @tableHTML NVARCHAR(MAX);
--write your Select query here
IF @@ROWCOUNT > 0
begin
SET @tableHTML =
N'<br>The following Quotations that were due today have been received : <br><br>'+
N'<table>' +
N'<tr bgcolor="#004251"><th>Quotation No.</th><th>Campus</th>' +
N'<th>Department</th><th>Title</th><th>Supplier</th>' +
N'<th>Currency</th><th>Price</th></tr>' +
CAST ( ( SELECT td = QuotationReferenceNum, '',
td = Campus, '',
td = Department, '',
td = Title, '',
td = FirstName, '',
td = Currency, ''
FROM Table X
WHERE <<Your Condition>>
ORDER BY QuotationReferenceNum ASC
FOR XML PATH('tr'), TYPE
) AS NVARCHAR(MAX) ) +
N'</table>' ;
exec msdb.dbo.sp_send_dbmail @profile_name='YourProfileName',
@recipients= '[email protected]',
@copy_recipients = '[email protected]',
@blind_copy_recipients = '[email protected]',
@subject='Quotation Close Summary',
@body = @tableHTML,
@body_format = 'HTML'
end
COMMIT
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句