Want to trigger Automate reply after click on a link in Outlook mail

╄→尐↘猪︶ㄣ 提交于 2019-12-12 04:14:52

问题


I am doing an Automation on outlook where End user will receive a mail where their will be a link by clicking on which an auto reply mail will be trigger and go to respective person. The code i Tried So far is mentioned below.

Sub MailURL()

Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
strbody = "<HTML><BODY>"
strbody = strbody & "xxx@xxx.com"
strbody = strbody & "</BODY></HTML>"
On Error Resume Next
With OutMail
    .to = "abc.domain.com"
    .Subject = "Testing URL"
    .HTMLBody = strbody
   ' .Send
   .Display
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing

End Sub   

I understand that it is considered as a Spamming, but that was a requirement for our project, where we will send a mail with some data to end user and if user need some change in that data then he can click on that link and we receive a mail with requested changes so we make changes and update it in database. Thanks.


回答1:


If I understand what you want, you need to add a link on the body that if clicked, will create a new mail with a pre-defined recipient. If that is so, this part:

"xxx@xxx.com"

should be:

"<a href=""mailto:xxx@xxx.com"">Relpy here</a>"

You can also add a subject like this:

"<a href=""mailto:xxx@xxx.com?subject=Change Request"">Relpy here</a>"

HTML syntax to add hyperlink is using <a href="yourlink">your_linked_text</a>.
In your case, you need to add mailto: in front of the linked email address to create a new mail.

Note: This will not automatically send the reply (as you've said that can be considered spamming so let's not do that.)




回答2:


here is a revision of your code

it worked for me (outlook2016), once i changed abc.domain.com to abc@domain.com

the "OutMail.Send" statement put the message into the outbox

the "OutMail.Display (True)" statement put the "new email" window on top of all other windows so that the user could verify the info and click "send"

Sub MailURL()

    Dim strbody As String

    strbody = "<HTML><BODY>"
    strbody = strbody & "xxx@xxx.com"
    strbody = strbody & "</BODY></HTML>"

    Dim OutMail As Outlook.MailItem                  ' define the actual object ... then "help info" pops up on screen as you type
    Set OutMail = Application.CreateItem(olMailItem) ' "Application"  object already exists

    With OutMail
        .To = "abc@domain.com"
        .Subject = "Testing URL"
        .HTMLBody = strbody
' you can use only one of the following two lines
'        .Send                                        ' this puts the email message into the outbox
        .Display (True)                              ' this show the email on top of everything else. just have the user click "send"
    End With

    Set OutMail = Nothing

End Sub


来源:https://stackoverflow.com/questions/44696333/want-to-trigger-automate-reply-after-click-on-a-link-in-outlook-mail

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!