Connecting Tech Pros Worldwide Help | Site Map

How to send email without displaying it ...

Ronny Sigo
Guest
 
Posts: n/a
#1: Nov 12 '05
Hello all,
Can anyone tell me how to prevent my mailprog to display the mail, and just
send it ?
The code I use is below
Any help appreciated ..
Thanks
Ronny Sigo

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 Const SW_SHOW = 5

Public Function OpenEmail(EmailAddress As String, _
Optional Subject As String, Optional Body As String) _
As Boolean

Dim lWindow As Long
Dim lRet As Long
Dim sParams As String

sParams = EmailAddress
If LCase(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

lRet = ShellExecute(lWindow, "open", sParams, _
vbNullString, vbNullString, SW_SHOW)

OpenEmail = lRet = 0

End Function



Ruskin Hardie
Guest
 
Posts: n/a
#2: Nov 12 '05

re: How to send email without displaying it ...


If you are using outlook (version 98 or higher), then this will work fine;

Sub SendMessage(myRecipient As String, _
mySubject As String, _
Optional myBody As String, _
Optional myFileName As String)

On Error Resume Next

Dim myObject As Object
Dim myItem As Object

Set myObject = CreateObject("Outlook.Application")
Set myItem = myObject.CreateItem(0)

With myItem
.Subject = mySubject
.To = myRecipient
If Trim(myBody) <> "" Then
.Body = myBody
End If
If Trim(myFileName) <> "" Then
If Dir(myFileName) <> "" Then
.Attachments.Add (myFileName)
End If
End If
.Send
End With

Set myItem = Nothing
Set myObject = Nothing
End Sub


"Ronny Sigo" <ronny.sigo@example.invalid> wrote in message
news:3fa54623$0$22171$ba620e4c@reader3.news.skynet .be...[color=blue]
> Hello all,
> Can anyone tell me how to prevent my mailprog to display the mail, and[/color]
just[color=blue]
> send it ?
> The code I use is below
> Any help appreciated ..
> Thanks
> Ronny Sigo
>
> 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 Const SW_SHOW = 5
>
> Public Function OpenEmail(EmailAddress As String, _
> Optional Subject As String, Optional Body As String) _
> As Boolean
>
> Dim lWindow As Long
> Dim lRet As Long
> Dim sParams As String
>
> sParams = EmailAddress
> If LCase(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
>
> lRet = ShellExecute(lWindow, "open", sParams, _
> vbNullString, vbNullString, SW_SHOW)
>
> OpenEmail = lRet = 0
>
> End Function
>
>
>[/color]


Closed Thread