Skip to content
Andrew Lambert edited this page Jan 14, 2023 · 7 revisions

This method sends a text email using SMTP.

Function SendEmail(ToAddress As String, FromAddress As String, Subject As String, MessageBody As String, SMTPURL As String) As Integer
  Dim CRLF As String = EndOfLine.Windows
  Dim curl As New cURLClient
  Dim r As New libcURL.ListPtr
  r.Append("<" + ToAddress + ">")
  If Not curl.SetOption(libcURL.Opts.MAIL_RCPT, r) Then Return curl.LastError
  If Not curl.SetOption(libcURL.Opts.MAIL_FROM, FromAddress) Then Return curl.LastError
  Dim Data As String = _
  "Date: Mon, 18 May 2015 21:54:29 +1100" + CRLF + _
  "To: <" + ToAddress + ">" + CRLF + _
  "From: <" + FromAddress + ">" + CRLF + _
  "Subject: " + Subject + CRLF + CRLF + _
  MessageBody + CRLF + CRLF
  
  If Not curl.Put(SMTPURL, Data) Then Return curl.LastError
End Function

Using the method:

  Dim URL As String = "smtp://SMTPUSERNAME:SMTPPASSWORD@mail.example.net:587"
  Dim i As Integer = SendEmail("root@example.net", "user@example.org", "Test Message", "Hello, world!", URL)
  If i <> 0 Then
    MsgBox(libcURL.FormatError(i))
  End If
Clone this wiki locally