Prolateral Consulting Ltd
Prolateral Consulting Ltd
Knowledgebase Articles
Setup examples

Prolateral offers primary and backup domain (DNS) services, with servers in key geographic locations providing the best service possible.


How do I send an email using the outMail API in Microsoft Visual Basic .NET?
How do I send an email in VB .NET with a RESTful API?


The following example of code assumes you have already got a fully functional development environment, and you have working knowledge of Visual Basic and the .NET Libraries.

In your VS Solution you will need to add the NuGet package Newtonsoft.JSON.

Example code outmail-send.vb

' outmail-send.vb
' This example will send an email using the outmail RESTful API.

Imports Newtonsoft.Json
Imports System
Imports System.Collections.Generic
Imports System.Net.Http
Imports System.Net.Http.Headers
Imports System.Text

Module Program

    Private Const apiSecretKey As String = "YOUR_SECRET_API_KEY"

    Private Const apiUrl As String = ""

    Sub Main(args As String())

        Dim toAddress As List(Of String) = New List(Of String)

        ' Create the New Email Message
        Dim newMessage As Dictionary(Of String, Object) = New Dictionary(Of String, Object)

        newMessage.Add("api_key", apiSecretKey)
        newMessage.Add("to", toAddress)
        newMessage.Add("sender", "")
        newMessage.Add("subject", "Sending via Outmail API")
        newMessage.Add("text_body", "This is the text message body")
        newMessage.Add("html_body", "<body><h1>This is the HTML message</h1></body>")

        ' Convert the Dictionary to Json
        Dim newMessageJsonStr As String = JsonConvert.SerializeObject(newMessage, Formatting.Indented)

        ' Create HTTP resource
        Dim client As New HttpClient()

        ' Add an Accept header for JSON format.
        client.DefaultRequestHeaders.Add("ContentType", "application/json")

        ' Create the content
        Dim content = New StringContent(newMessageJsonStr, Encoding.UTF8, "application/json")

        ' Do the POST
        Dim response As HttpResponseMessage = client.PostAsync(apiUrl, content).Result

        ' Check the result for a valid HTTP 200 success And process the returned result
        ' Or handler the failure.
        If (response.IsSuccessStatusCode) Then
            Dim jsonResponseStr = response.Content.ReadAsStringAsync().Result
            Dim jsonResponse As Object = JsonConvert.DeserializeObject(jsonResponseStr)
            If jsonResponse.ContainsKey("data") Then
                Console.WriteLine("status     = {0}", jsonResponse("status"))
                Console.WriteLine("message id = {0}", jsonResponse("data")("email_id"))
                Console.WriteLine("response = {0}", response)
                Console.WriteLine("json response = {0}", jsonResponse)
            End If
            ' Get the Json Error response And convert it
            Dim jsonResponseStr = response.Content.ReadAsStringAsync().Result
            Dim jsonResponse As Object = JsonConvert.DeserializeObject(jsonResponseStr)
            Console.WriteLine("status  = {0}", jsonResponse("status"))
            Console.WriteLine("message = {0}", jsonResponse("message"))
            Console.WriteLine("error   = {0}", jsonResponse("errors"))
            Console.WriteLine("{0} ({1})", response.StatusCode, response.ReasonPhrase)
        End If

        'Dispose once all HttpClient calls are complete.

    End Sub
End Module


Summary of server details

Outgoing server

As provided in your signup email.

Outgoing server protocol


Outgoing server port

25, 465, 587, 2525 or 8025

Authentication Type

Basic Authentication, SSL and TLS supported


As provided


As provided

like it, love it, then share it. Share this article on social media.

Did you enjoy this article?


The Origin of this information may be internal or external to Prolateral Consulting Ltd. Prolateral makes all reasonable efforts to verify this information. However, the information provided in this document is for your information only. Prolateral makes no explicit or implied claims to the validity of this information. Any trademarks referenced in this document are the property of their respective owners.