[AccessD] ShellExecute to send short e-mail vianon-MSemailclients...

MartyConnelly martyconnelly at shaw.ca
Fri Nov 4 12:20:20 CST 2005


Here is a VBA method that works without MAPI under certain conditions
and no email client is needed. I don't know if this will help.

You need CDOSYS (WinXP or Win2000)
You may have to be within a network domain
You need the SMTP server address
You must have an Internet Connection running


'The example code is using CDOSYS (CDO for Windows 2000 or XP).
'I dont think I would want to go back to CDONTS for earlier systems
'It does not depend on MAPI or CDO or Outlook
'It does not use your mailbox to send email.
' So you can send mail without a mail program or mail account
' This code builds the message and drops it into a pickup directory,
' and the SMTP service running on the machine
' picks it up and send it out to the internet.

'So why use CDO code instead of Outlook automation or
'Application.SendMail in VBA.
' It doesn't matter what Mail program you are using (It uses the
'SMTP server).
' It doesn't matter what Office version you are using.
' supposedly you can send an object or file in the body of the mail
'(some mail programs can't do this)
' haven't verified this
' You can send any file attachment you like.
' No Outlook Security warning so no need for Redemption

' You probably won't have your mail server full expanded smtp address
'If you go into netscape mail or outlook and look for the smtp name
'It will look like mine, "shawmail" or "shawnews" this dns resolves
'to "shawmail.cg.shawcable.net" CDO doesn't resolve this short name so
'The quickest way to get this actual address without using registry et al.
'is run cmd and ping "shawmail" to return full qualified smtp address.
'This code wont run exactly unless you are on cable and signed on in
'the Shaw or whatever is your domain, your cable modem is a node in
'their domain

Sub SendCDO()
' This example use late binding of CDOSys, you don't have to set a
' Reference
' You must be online to net when you run the sub
' You must be running WinXP or Win2000
Dim cdoMessage As Object
Dim objCDOMail As Object
Dim strschema As String
On Error GoTo ErrorHandler
' Enable error-handling routine.
'
Set cdoMessage = CreateObject("CDO.Message")
Set objCDOMail = CreateObject("CDO.Configuration")
strschema = "http://schemas.microsoft.com/cdo/configuration/"
objCDOMail.Load -1 ' CDO Source Default
'If you have illegal or wrong smtp address here it will run for 30-
'60 seconds and finally give a transport error
With objCDOMail.Fields
.Item(strschema & "sendusing") = 2 ' cdoSendUsingPort
.Item(strschema & "smtpserver") = "shawmail.cg.shawcable.net" ' "Your 
SMTP server address here"
.Item(strschema & "smtpserverport") = 25 'specify port number
.Update
End With

With cdoMessage
Set .Configuration = objCDOMail
.to = "mconn at gmail.com"
.From = "Winnie The Pooh <mconn at shaw.ca>"
.CC = ""
.BCC = ""
.Subject = "This is another test from marty"
.TextBody = "This is the text in the body just cdo defaults"
.AddAttachment "C:\temp2\rptSampleCount.rtf"
.AddAttachment "C:\temp2\frontimage.jpeg"
.send
End With
debug.print "Done"
Set cdoMessage = Nothing
Set objCDOMail = Nothing
Exit Sub ' Exit to avoid handler.
ErrorHandler: ' Error-handling routine.
Debug.Print Err.Number & "-" & Err.Description
Set cdoMessage = Nothing
Set objCDOMail = Nothing
Exit Sub
End Sub

-- 
Marty Connelly
Victoria, B.C.
Canada






More information about the AccessD mailing list