Send EMail thru VB without User Intervention

From: Dennis (DBARNETT_at_CCC.HSHS.ORG)
Date: 05/20/04


Date: 20 May 2004 10:56:15 -0700

Hi

I found the code snippet below on this newsgroup and it works well,
as long as the user clicks the send button.

Can anyone tell me how to send the email behind the scenes without it
coming up and requiring user intervention?

Thanks
Dennis

Const SW_SHOWNORMAL = 1
Const kgCrLf = "%0D%0A"
Const Nil = vbNullString

Private Declare Function ShellExecute Lib "shell32.dll" Alias
"ShellExecuteA" _
   (ByVal hwnd As Long, _
   ByVal lpOperation As String, _
   ByVal lpFile As String, _
   ByVal lpParameters As String, _
   ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

Private Sub Command1_Click()
   If ShellExecute(Me.hwnd, "open", _
                   "mailto:me@myemail.org" & _
                   "?Subject=Test Email generated from VB ..." & _
                   "&cc=you@youremail.org" & _
                   "&bcc=him@hisemail.org" & _
                   "&body=This is line one" & kgCrLf & "Line two", _
                   Nil, _
                   Nil, _
                   SW_SHOWNORMAL) <= 32 Then
      MsgBox "Some error message"
   End If
End Sub



Relevant Pages

  • Re: Writing to a file using API
    ... Const FILE_ATTRIBUTE_TEMPORARY = &H100 ... "SetVolumeLabelA" (ByVal lpRootPathName As String, ... Private Declare Function WriteFile Lib "kernel32" (ByVal hFile As Long, ...
    (microsoft.public.vb.winapi)
  • Re: Setting Default Values for Printer
    ... Const CLIP_DEFAULT_PRECIS = 0 ... lpPrintTemplateName As String ... Private Declare Function PrintDialog Lib "comdlg32.dll" _ ... Dim lpDevMode As Long, lpDevName As Long ...
    (microsoft.public.vb.general.discussion)
  • Re: txt-file is UTF8 or DOS.
    ... (ByVal lpBuffer As String, ByVal cb As Long, lpi As Long) ... Const sFile$ = "UTF16toDOS.txt" ... Buffer = String, Chr) ... Private Declare Function MultiByteToWideChar Lib "kernel32" _ ...
    (microsoft.public.excel.programming)
  • avicap32 problem [CROSSPOST]
    ... I want to build a video chat application but I encountered a problem ... ... Const WS_CHILD As Long = &H40000000 ... Private Declare Function capGetDriverDescriptionA Lib "avicap32.dll" (ByVal ... Private Sub LoadDeviceList() ...
    (microsoft.public.vb.winapi)
  • Re: txt-file is UTF8 or DOS.
    ... (ByVal lpBuffer As String, ByVal cb As Long, lpi As Long) ... Const sFile$ = "UTF16toDOS.txt" ... Buffer = String, Chr) ... Private Declare Function MultiByteToWideChar Lib "kernel32" _ ...
    (microsoft.public.excel.programming)