vineet singh
vineet singh

Reputation: 51

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

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 & "[email protected]"
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.

Upvotes: 0

Views: 3411

Answers (2)

L42
L42

Reputation: 19727

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:

"[email protected]"

should be:

"<a href=""mailto:[email protected]"">Relpy here</a>"

You can also add a subject like this:

"<a href=""mailto:[email protected]?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.)

Upvotes: 1

jsotola
jsotola

Reputation: 2278

here is a revision of your code

it worked for me (outlook2016), once i changed abc.domain.com to [email protected]

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 & "[email protected]"
    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 = "[email protected]"
        .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

Upvotes: 0

Related Questions