Send email regardless of whether Outlook is running

snakie

Registered User.
Local time
Today, 04:47
Joined
Jun 18, 2009
Messages
14
Hi,

I am just wondering, I have a database which can be used to send emails via Outlook. However, it only works if Outlook is already running in the background.

If Outlook is not already running, I get error 462 (The remote server machine does not exist or is unavailable).

Is there any way that I could avoid this from happening?

Any advice you could provide is much appreciated.

Many thanks,

Joe
 
Use CDO. Install it under Outlook from add or remove programs. Here is the code I am currently using

Code:
Dim mydb As DAO.Database
Dim rs As DAO.Recordset
Set mydb = CurrentDb()
Set rs = mydb.OpenRecordset("6g daily email query", dbOpenSnapshot)
With rs
.MoveFirst
Do Until rs.EOF
If IsNull(rs.Fields(0)) = False Then
Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "Todays Testing for " & rs.Fields(1)
objMessage.From = "Project Testing <[EMAIL="bwbsl.testing@bwbsl.co.uk"]bwbsl.testing@bwbsl.co.uk[/EMAIL]>"
objMessage.Sender = "Project Testing <[EMAIL="bwbsl.testing@bwbsl.co.uk"]bwbsl.testing@bwbsl.co.uk[/EMAIL]>"
objMessage.To = rs.Fields(0)
objMessage.TextBody = "Below is a listing of testing work for you Today. If you need a detailed listing of tests, please contact the Testing Team who will provide this.  " & vbCrLf & _
                    "Number of Tests Due to Complete Today: " & rs.Fields(2) & vbCrLf & _
                    "Number of Tests Due to Start Today: " & rs.Fields(3) & vbCrLf & _
                    "Number of Tests Past Planned Completion Date: " & rs.Fields(4) & vbCrLf & _
                    "Number of Tests Past Planned Start Date: " & rs.Fields(5) & vbCrLf & _
                    "Number of Tests Due to Start Tomorrow Prep Not Complete: " & rs.Fields(6)
 

objMessage.Configuration.Fields.Item _
("[URL]http://schemas.microsoft.com/cdo/configuration/sendusing[/URL]") = 2

objMessage.Configuration.Fields.Item _
("[URL]http://schemas.microsoft.com/cdo/configuration/smtpserver[/URL]") = "smtp.server.com"

objMessage.Configuration.Fields.Item _
("[URL]http://schemas.microsoft.com/cdo/configuration/smtpserverport[/URL]") = 25
objMessage.Configuration.Fields.Update
 
objMessage.Send
End If
.MoveNext
Loop
End With
rs.Close
Set mydb = Nothing
Set rs = Nothing
 
Hi

I have some outlook code that will place the email in the outbox if outlook is closed. I'll post it later when I get home

Nidge
 

Users who are viewing this thread

Back
Top Bottom