Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

e-mailing From Access - Not Using Outlook

Status
Not open for further replies.

ChrisBelzona

Programmer
Oct 25, 2000
137
0
0
GB
Hi

Has anyone written code for sending automatic e-mails from within access not using Outlook?

Currently I am fixing the system by creating two text files replicating an e-mail header and body file and exporting it to the mail server (in) directory.

This works most of the time however there are occasions when it doesn't and I'm looking for a more reliable method. Using Outlook is out of the question.

Any pointers would be most helpful.

Cheers

Chris
 
Set your Windows default Email package to the one you want to use and then you can use DoCmd.SendObject. If your default is Outlook then look into an API that will switch it to the one you want to use and then back to Outlook.

Uncle Jack
 
Uncle Jack

Sorry did not explain myself to well I don't want to use the DoCmd.SendObject method. I've tried that and again does not work to well with our sustems.

Just looking for any other options.

Cheers

Chris
 
Try this, it came from a Microsoft knowledge base posting and I have modified slightly. MS acknowledges issues with the SendObject command in Access and suggested this. Beware of text wrapping in this.


'This procedure allows the user to send email via the MS Outlook object.

'Usage of this procedure requires that the Outlook library file MSOUTL9.OLB be present
' in the following directory:
' c:\Program Files\Microsoft Office\Office


'Syntax for usage is as follows:

'SendMessage <AttachmentPath>, <mTO>, <mCC>, <mSubject>, <mMessage>
' All parameters are optional.
' Example:
' Code from calling procedure:
'
' strTo = &quot;First Last&quot; ' Names need to be valid in your Outlook listings
' strCC = &quot;First Last&quot;
' strSubject = &quot;Photo Dir Error!&quot;
' strMessage = &quot;There is an error in the following spread: &quot; & Chr(13) & Chr(13)
' strMessage = strMessage & &quot;Spread: &quot; & tempSpread & &quot; Shot: &quot; & tempShot & Chr(13) & Chr(13)
' strMessage = strMessage & &quot;One of the pack numbers in this shot has been deleted.&quot;

' SendMessage , strTo, strCC, strSubject, strMessage

Sub SendMessage(Optional AttachmentPath, Optional mTo, Optional mCC, Optional mSubject, Optional mMessage)
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
Dim scTo As String

' Create the Outlook session.
Set objOutlook = CreateObject(&quot;Outlook.Application&quot;)

' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

With objOutlookMsg
' Add the To recipient(s) to the message.
scTo = &quot;charter&quot;
Set objOutlookRecip = .Recipients.Add(mTo)

objOutlookRecip.Type = olTo

' Add the CC recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add(mCC)
objOutlookRecip.Type = olCC

' Set the Subject, Body, and Importance of the message.
.Subject = mSubject
.Body = mMessage
'.Importance = olImportanceLow 'use for low importance
'.Importance = olImportanceNormal 'use for normal importance
.Importance = olImportanceHigh 'High importance

' Set read receipt requested.
'.ReadReceiptRequested = True 'for read receipt

' Add attachments to the message.
If Not IsMissing(AttachmentPath) Then
Set objOutlookAttach = .Attachments.Add(AttachmentPath)
End If

' Resolve each Recipient's name.
For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
If Not objOutlookRecip.Resolve Then
objOutlookMsg.Display
End If
Next
.Send

End With
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
End Sub
 
Thanks for the input, but i've found a app used on asp pages that allows e-mail to be created using vba and sends direct to the smtp mail server, It can be also used within an access database without using outlook.

cheers for your help

Chris Russell
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top