Furqan Sehgal
Furqan Sehgal

Reputation: 4997

How to call public function

I have a public function to call default email client.

Public Function OpenEmail(ByVal EmailAddress As String, Optional ByVal Subject As String = "", Optional ByVal Body As String = "") As Boolean
    Dim bAns As Boolean = True
    Dim sParams As String
    sParams = EmailAddress
    If LCase(Strings.Left(sParams, 7)) <> "mailto:" Then _
        sParams = "mailto:" & sParams

    If Subject <> "" Then sParams = sParams & _
          "?subject=" & Subject

    If Body <> "" Then
        sParams = sParams & IIf(Subject = "", "?", "&")
        sParams = sParams & "body=" & Body
    End If
End Function

Then in Button_click, I put

 OpenEmail("[email protected]", "Subject", Body:=" of my message")

But I am unable to call the function. I want to open the client when I click button1 Thanks

Upvotes: 1

Views: 12156

Answers (1)

KV Prajapati
KV Prajapati

Reputation: 94645

If this method (function) is defined in the Test class then create an instance of Test and call it.

public class Test
Public Function OpenEmail(ByVal EmailAddress As String, Optional ByVal Subject As String = "", Optional ByVal Body As String = "") As Boolean
 ....
End Function
End Class

Code in button'c click handler:

Dim tst as New Test
tst.OpenEmail("[email protected]", "Subject", Body:=" of my message")

PS: Use System.Net.Mail API to send email.

EDIT: To open default mail-client:

Process.Start("mailto:[email protected]?subject=Message Title&body=Message Content")

Upvotes: 1

Related Questions