您的位置:首页 > 大数据 > 人工智能

Using a LotusScript agent to reply to mail from the Internet

2016-08-24 20:45 1836 查看


http://www-01.ibm.com/support/docview.wss?uid=swg21230700


Technote (FAQ)


Question

In your Lotus Notes® mail file, you want to automatically reply to mail messages that are received from Internet addresses. For example, you want to send a "Thank you for your inquiry" message to all who send you mail from the Internet. How can you do this?


Answer

You can use a LotusScript agent to test for Internet addresses and limit the replies to those senders. For example, the agent below would use the trigger of "After new mail arrives." The agent tests for an Internet address and then sends a reply to the sender
with a "Thank you for your inquiry" response.
NOTE: The code below is a sample script provided to illustrate one way to approach this issue.
In order for this example to perform as intended, the script must be laid out exactly as indicated below. IBM Support cannot customize this script for a customer's own configuration.

In the script, you can customize the BodyText variable as desired. The code can be placed in the Initialize event.

Dim session As New NotesSession 

Dim db As NotesDatabase 

Dim col As NotesDocumentCollection 

Dim doc As NotesDocument 

Dim MailDoc As NotesDocument 

Dim Body As NotesRichTextItem 

Dim OldBody As NotesRichTextItem 

Dim OriginalFromAddress As String 

Dim Subject As String 

Dim BodyText As String 

'This is the body of the email, Chr(10) indicates a new line 

'you can change the body to whatever you want following this format 

BodyText = "Thank you for your inquiry." + Chr(10) +_ 

"This is an automatically generated response. Please do not reply." + Chr(10) +_ 

"We will contact you shortly regarding your inquiry." + Chr(10) +_ 

"Regards," + Chr(10)+_ 

"John Doe" 'SET THIS TO DESIRED NAME 

'set objects

Set db = session.CurrentDatabase 

Set col = db.UnprocessedDocuments 

Set doc = col.GetFirstDocument 

'set the subject of the email to go out

Subject = "Re: " + doc.GetItemValue("Subject")(0) 

'loop through the document collection

While Not doc Is Nothing

'check the address to see if it contains an @ sign

If doc.HasItem("SMTPOriginator") Then

OriginalFromAddress = doc.GetItemValue("SMTPOriginator")(0)

Elseif doc.HasItem("From") Then

OriginalFromAddress = doc.GetItemValue("From")(0)

Else

Goto nextdoc

End If

'if an @ sign is found, send a reply

If Instr(OriginalFromAddress,"@") <> 0 Then

'create a new mail document

Set MailDoc = db.CreateDocument 

'set the subject and from fields

Call MailDoc.ReplaceItemValue("Subject", Subject) 

'set the body and append the body from the original email

Set OldBody = doc.GetFirstItem("body") 

Set body = MailDoc.CreateRichTextItem("body") 

Call body.AppendText(bodyText) 

Call body.AddNewline(2) 

Call body.AppendRTItem(oldBody) 

'send the document

Call MailDoc.Send(False,OriginalFromAddress)

End If

Nextdoc:

'update the processedDoc flag so that this document isn't processed 

'again on a subsequent run 

Call session.UpdateProcessedDoc(doc) 

'get the next document in the collection

Set doc = col.GetNextDocument(doc)

Wend
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐