简体   繁体   English

运行脚本以附加电子邮件的主题和正文

[英]Run Script to Append Subject and Body of Email

I am [attempting to] learn how to write a script in Outlook that when a certain category is set on an email:我 [试图] 学习如何在 Outlook 中编写一个脚本,当在电子邮件上设置某个类别时:

  1. Append the Subject with " PROJ=5"用“PROJ=5”附加主题
  2. Append the Body with about 10 lines of text在正文中添加大约 10 行文本
  3. Send email.发电子邮件。

My goal is to mark an email with a category and forward the email to our ticketing system.我的目标是用类别标记电子邮件并将电子邮件转发到我们的票务系统。

I'm not really having any luck with the samples I have found.我对我找到的样本并不抱有任何运气。

Samples (URL) I have tried (Copied code and updated relevant fields):我尝试过的示例(URL)(复制代码并更新相关字段):

  1. Append the Subject with " PROJ=5"用“PROJ=5”附加主题

MailItem.Subject Property Returns a String indicating Outlook item. MailItem.Subject Property返回一个字符串,指示 Outlook 项目。 Read/write.读/写。

Example 例子

Item.Subject = "PROJ=5" & Item.Subject
  1. Append the Body with about 10 lines of text在正文中添加大约 10 行文本

Example例子

Dim olBody As String
olBody = "<HTML><BODY><P>Append the Body with about 10 lines of text</P>" & vbNewLine & vbNewLine & _
                     "<P>Append the Body with about 10 lines of text</P></HTML></BODY>" & vbNewLine

 olForward.HTMLBody = olBody & vbCrLf & olForward.HTMLBody
  1. Send / Forward Email发送/转发电子邮件

Example例子

'// 
Set olForward = Item.Forward
'// add Recipent
olForward.Recipients.Add "email@domain.com"
'// Send or your use .Dispaly 
olForward.Send

Run a Script Rule运行脚本规则

To use Rule Wizard , your macro has to have the expected parameter:要使用Rule Wizard ,您的宏必须具有预期的参数:

Example例子

Public Sub ItemForward(Item As Outlook.MailItem)

End Sub

Helpful article in MSDN Outlook 2010 VBA MSDN Outlook 2010 VBA 中的有用文章

Complete Code Test on Outlook 2010 VBAOutlook 2010 VBA上完成代码测试

Please make sure your References are set to run action script (Tools > References)请确保您的参考资料设置为运行动作脚本(工具 > 参考资料)

Option Explicit
'// Run Action Script

Public Sub ItemForward(Item As Outlook.MailItem)
    Dim olApp As Outlook.Application
    Dim olForward As MailItem
    Dim olBody As String

    Set olApp = CreateObject("Outlook.Application")

    '// Append the Subject
    Item.Subject = "PROJ=5 " & Item.Subject
    Item.Save

     Set olForward = Item.Forward
    '// add Recipent
    olForward.Recipients.Add "Test@mail.com"


    olBody = "<HTML><BODY><P>Append the Body with about 10 lines of text</P>" & vbNewLine & vbNewLine & _
                         "<P>Append the Body with about 10 lines of text</P>" & vbNewLine & _
                         "<P>Append the Body with about 10 lines of text</P>" & vbNewLine & _
                         "<P>Append the Body with about 10 lines of text</P>" & vbNewLine & _
                         "<P>Append the Body with about 10 lines of text</P>" & vbNewLine & _
                         "<P>Append the Body with about 10 lines of text</P>" & vbNewLine & _
                         "<P>Append the Body with about 10 lines of text</P>" & vbNewLine & _
                         "<P>Append the Body with about 10 lines of text</P>" & vbNewLine & _
                         "<P>Append the Body with about 10 lines of text</P>" & vbNewLine & _
                         "<P>Append the Body with about 10 lines of text</P></HTML></BODY>" & vbNewLine


    '// Forward Email
    olForward.HTMLBody = olBody & vbCrLf & olForward.HTMLBody
    '// Send or your use .Dispaly
    olForward.Send
    Set olApp = Nothing
    Set olForward = Nothing
End Sub

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

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