send email with / from MS EXCEL VBA macro

This page provides information on use of utility Command line email in Microsoft Excel VBA macro (Visual Basic for Applications). By using Febooti Command line email you can:

  • Send email message using plain text or HTML message with embedded pictures.
  • Send unlimited number of attachments.
  • Use return codes to check success or failure.
  • Works on Microsoft Windows (98 / Me / NT / 2000 / XP / Vista / Windows 7 / 2003 / 2008) including all server versions.
  • And many more options...

Example for MS Excel VB script:

Sub sending_email()
  ' Send Excel e-mail and output the result.

  Dim server
  Dim subj
  Dim body
  Dim command

  ' Define all email parameters.

  server = " -SMTP smtp.sender.com -PORT 25"
  subj = "EXCEL e-mail"

  body = """This is <I>HTML / MIME</I> e-mail message "
  body = body & "sent from MS EXCEL VB script<BR>"
  body = body & "using <B>Febooti Command line email</B>"""

  command = "febootimail.exe -HTML -FROM excel-macro@sender.com "
  command = command & "-TO john@recipient.com "
  command = command & "-SUBJ " & subj & " -BODY " & body & server

  ' Passing one long line to Scripting object.
  ' If there is need to add additional parameters, do it before.


  Set wsShell = CreateObject("wscript.shell")
  Set proc = wsShell.Exec(command)

  Dim s : s = ""
  Do While proc.Status = 0
    ' Wait until e-mail is sent...
    Application.Wait (Now + TimeValue("0:00:01"))
  Loop

  ' Use proc.ExitCode to check for returned %errorlevel%

  s = s & "StdOut=" & proc.StdOut.ReadAll()
  s = s & Chr(13) & Chr(10) & "ExitCode=" & proc.ExitCode
  MsgBox (s)

  Set wsShell = Nothing
  Set proc = Nothing

  ' Error Level values and descriptions are available at:
  ' www.command-line-email.com/online-help/batch-file-errorlevel.html

End Sub
Additional Command line email notes and resources:
Send command line email from PHP scriptSend command line email from ASP scriptSend command line email from MS FoxPro script
Email from PHP, ASP and FoxPro

Please do not hesitate to contact our support department with any possible further questions or to solve practical issues connected with Command line email.

Copyright © 2001-2011 Febooti Software. All rights reserved. Last updated: August 31, 2009