[AccessD] Sending Email via Code

MartyConnelly martyconnelly at shaw.ca
Tue Nov 29 00:05:54 CST 2005


You could try blat from a command line and shell
http://www.blat.net/

I use this one has certain restictions see comments

'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 wont 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, and 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 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 = "macon at g..."
.From = "Winnie The Pooh <macon at s...>"
.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

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

Another method

http://freevbcode.com/ShowCode.Asp?ID=109


Lonnie Johnson wrote:

>Is there a way to send email via code without invoking outlook?
>
>I have an application that may run on a machine with outlook and it may run on a machine with groupwise. I need something more generic than the Create Outlook Object process.
>   
>  I am needing more than the SendObject also because I am exporting two queries into one one file to create two excel sheets in a workbook. 
>
>Thanks. 
>
>
>
>May God bless you beyond your imagination!
>Lonnie Johnson
>ProDev, Professional Development of MS Access Databases
>Visit me at ==> http://www.prodev.us
>
>
>  
>

-- 
Marty Connelly
Victoria, B.C.
Canada






More information about the AccessD mailing list