剩余邮件代理(Remainder Mail agent)

编程入门 行业动态 更新时间:2024-10-23 04:41:16
剩余邮件代理(Remainder Mail agent)

我有3个字段地址,状态,ReportingDate的表单。

地址字段包含必须发送mil的ID。

现在我创建了一个代理,当状态不完整时,它应该邮寄到地址字段中的数据,并且报告日期恰好是今天日期之前的7天。

我的代码:

Option Public Option Declare Sub Initialize Dim sess As New NotesSession Dim db As NotesDatabase Dim doc As NotesDocument Dim timestamp As New NotesDateTime("Today") Dim Noresponsedate As NotesDateTime Dim vw As NotesView Dim diff As Integer Dim SendTo As Variant Call timestamp.SetNow() Set db = sess.CurrentDatabase Set vw = db.GetView( "data" ) Set doc = vw.GetFirstDocument() While Not doc Is Nothing If doc.Status(0) = "Incomplete" Then Call checktimedifference(doc) End if Set doc = vw.GetNextDocument(doc) wend End Sub Sub checktimedifference(doc As NotesDocument) Dim due As NotesDateTime Dim present As NotesDateTime Dim timecheck As variant Set due = New NotesDateTime ( "" ) Set present = New NotesDateTime ( "Today" ) timecheck = doc.ReportingDate(0) due.LSLocalTime = timecheck If due.TimeDifference (present) = -604800 Then Call sendmailtouser(doc) End If End Sub Sub sendmailtouser(doc As NotesDocument) Dim db As NotesDatabase Dim rtiitem As NotesRichTextItem Dim maildoc As NotesDocument dim recepient As variant Set maildoc = New NotesDocument( db ) Set rtiitem = New NotesRichTextItem( maildoc, "Body" ) recepient = doc.adress(0) maildoc.from = db.Title maildoc.form = "memo" maildoc.subject = "A Minor Injury Report:" & doc.Seq_No(0) & " needs your response" maildoc.SendTo = recepient Call rtiitem.AppendText( "Please respond to this Minor Injury Report" ) Call rtiitem.AddNewline( 2 ) Call rtiitem.AppendText( "Your response for the Minor Injury Report: " & doc.Seq_No(0) & " is required" ) Call rtiitem.AddNewline( 2 ) Call rtiitem.AppendText( "Please click on the following link to access the document.") Call rtiitem.AppendDocLink( doc, db.Title ) Call maildoc.Send(False) End Sub

当我在客户端上运行代理时,我收到以下错误:

请帮我解决错误并发送邮件给收件人。

I have form with 3 fields adress,status,ReportingDate.

Adress field contains the ID where the mil has to be sent.

Now I have created an agent where it should mail to the data present in adress field when status is incomplete and reporting date is exactly 7 days before todays date.

My Code:

Option Public Option Declare Sub Initialize Dim sess As New NotesSession Dim db As NotesDatabase Dim doc As NotesDocument Dim timestamp As New NotesDateTime("Today") Dim Noresponsedate As NotesDateTime Dim vw As NotesView Dim diff As Integer Dim SendTo As Variant Call timestamp.SetNow() Set db = sess.CurrentDatabase Set vw = db.GetView( "data" ) Set doc = vw.GetFirstDocument() While Not doc Is Nothing If doc.Status(0) = "Incomplete" Then Call checktimedifference(doc) End if Set doc = vw.GetNextDocument(doc) wend End Sub Sub checktimedifference(doc As NotesDocument) Dim due As NotesDateTime Dim present As NotesDateTime Dim timecheck As variant Set due = New NotesDateTime ( "" ) Set present = New NotesDateTime ( "Today" ) timecheck = doc.ReportingDate(0) due.LSLocalTime = timecheck If due.TimeDifference (present) = -604800 Then Call sendmailtouser(doc) End If End Sub Sub sendmailtouser(doc As NotesDocument) Dim db As NotesDatabase Dim rtiitem As NotesRichTextItem Dim maildoc As NotesDocument dim recepient As variant Set maildoc = New NotesDocument( db ) Set rtiitem = New NotesRichTextItem( maildoc, "Body" ) recepient = doc.adress(0) maildoc.from = db.Title maildoc.form = "memo" maildoc.subject = "A Minor Injury Report:" & doc.Seq_No(0) & " needs your response" maildoc.SendTo = recepient Call rtiitem.AppendText( "Please respond to this Minor Injury Report" ) Call rtiitem.AddNewline( 2 ) Call rtiitem.AppendText( "Your response for the Minor Injury Report: " & doc.Seq_No(0) & " is required" ) Call rtiitem.AddNewline( 2 ) Call rtiitem.AppendText( "Please click on the following link to access the document.") Call rtiitem.AppendDocLink( doc, db.Title ) Call maildoc.Send(False) End Sub

When I am running the agent on client I am getting the following error:

Please help me to solve the error and send mail to the recepients.

最满意答案

不使用任何错误处理是非常糟糕的做法。 但是你的错误最有可能发生在sendmailtouser- sub中,你可以在这里调暗一个名为db的本地notesdatabase-对象而不实际初始化它。

这条线

set maildoc = New NotesDocument( db )

将失败。 要么全局声明db并再次在初始化或昏暗的ses中设置它并再次设置db(最坏的情况是你必须为每个文件做这个)

Not using any error handling is very bad practice. But your error will most probably happen in the sendmailtouser- sub, where you dim a local notesdatabase- object named db without actually initializing it.

The line

set maildoc = New NotesDocument( db )

will fail. Either declare db globally and set it in your initialize or dim ses in that sub again and set db again (worst case as you have to do it for every document)

更多推荐

本文发布于:2023-08-07 02:15:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1458826.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:剩余   邮件   Remainder   Mail   agent

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!