[AccessD] Automating email

MartyConnelly martyconnelly at shaw.ca
Tue Feb 20 14:19:35 CST 2007


A couple of notes on this method

' 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
'The quickest way to get this actual address without using the registry
'is run cmd and ping "shawmail" to return full qualified smtp address.

'This code wont run exactly unless you are on cable or LAN and signed
'onto the Shaw ISP or whatever is your domain, your cable modem
'is a node inside the ISP domain. This wont run on a dialup


'If you have illegal or wrong smtp address here code will run for 30-
' 60 seconds and finally give a transport error


Your ISP may squawk if you send more than 100 Emails  an hour

This code runs for me via a cable modem

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


David Emerson wrote:

>Thanks Kath and Erwin,
>
>I eventually found some code that doesn't rely on outlook but uses 
>another file called CDOEx.dll.  It doesn't leave any items in outlook.
>
>In references you need to set the reference to Microsoft CDO for 
>Exchange 2000 Library
>
>Public Function SendCdoMsg()
>
>     On Error GoTo Err_SendCdoMsg
>
>     Dim msg As Message
>
>     Set msg = CreateObject("CDO.Message")
>
>     With msg
>         With .Configuration.Fields
>             .Item(cdoSMTPAuthenticate) = cdoAnonymous
>             .Item(cdoSendUsingMethod) = cdoSendUsingPort
>             .Item(cdoSMTPServer) = "smtp.xtra.co.nz"
>             .Item(cdoSMTPConnectionTimeout) = 10
>             .Item(cdoSMTPServerPort) = 25
>             .Update
>         End With
>         .Organization = "my"
>         .To = "you at yourprovider"
>         .Subject = "Example subject"
>         .TextBody = "Example body"
>         .From = "me at myprovider"
>         .AddAttachment ("d:\aaaatemp\accarch135.zip")
>         .Send
>     End With
>
>     Set msg = Nothing
>
>Exit_SendCdoMsg:
>     Exit Function
>
>Err_SendCdoMsg:
>     Select Case Err
>         Case 0
>             MsgBox "0 error", vbCritical, "Error heading"
>         Case Else
>             Call basErrorMsg("SendCdoMsg")
>     End Select
>     Resume Exit_SendCdoMsg
>
>End Function
>
>
>At 20/02/2007, you wrote:
>  
>
>>Hi David - I only use the .Display option in my apps so that the 
>>users can add some text to the email if they want to before it is 
>>sent, but .send WILL send the email depending on their Outlook preferences.
>>
>>ie. if they have [tools] [options] [mail delivery] 'Send immediately 
>>when connected' turned on, then yes, it will send.
>>
>>I haven;t found any way of that email not going into sent items though.
>>
>>Kath
>>
>>  ----- Original Message -----
>>  From: David Emerson
>>  To: accessd at databaseadvisors.com
>>  Sent: Tuesday, February 20, 2007 11:31 AM
>>  Subject: [AccessD] Automating email
>>
>>
>>  Group,
>>
>>  I have the following code to create an email message:
>>
>>  Public Function basSendEmail()
>>
>>       Dim outApp As Outlook.Application, outMsg As MailItem
>>
>>       Set outApp = CreateObject("Outlook.Application")
>>       Set outMsg = outApp.CreateItem(olMailItem)
>>
>>       With outMsg
>>           .To = "newsgrps at dalyn.co.nz"
>>           .Subject = "Test egas email"
>>           .Body = "Test message"
>>           .Send
>>       End With
>>
>>       Set outApp = Nothing
>>       Set outMsg = Nothing
>>
>>  End Function
>>
>>  This works fine but only puts the message into my Outlook outbox - it
>>  doesn't send it.  This may be because although I have outlook
>>  installed I do not use it (and it has not been set up).
>>
>>  However, my clients use outlook.  Will the above code automatically
>>  send out emails?
>>
>>  Another question - My client would prefer not to have copies in their
>>  outbox of the email being sent out (ultimately it will be to email
>>  out accounts and they don't want thousands of emails generated each
>>  month).  Is there a way for the messages not to appear in outlook?
>>
>>
>>  --
>>  AccessD mailing list
>>  AccessD at databaseadvisors.com
>>  http://databaseadvisors.com/mailman/listinfo/accessd
>>  Website: http://www.databaseadvisors.com
>>--
>>AccessD mailing list
>>AccessD at databaseadvisors.com
>>http://databaseadvisors.com/mailman/listinfo/accessd
>>Website: http://www.databaseadvisors.com
>>    
>>
>
>  
>

-- 
Marty Connelly
Victoria, B.C.
Canada




More information about the AccessD mailing list