Need help to send email using outlook

G

Guest

I have an database (access 2002 format) that send email using outlook 2002.
I have used the following code:

DoCmd.SendObject acSendNoObject, , , Email, , , Myvar, myVar2, True

Some users have upgraded to Outlook 2003 and now there is a strange behavior:

The emails are sent ok but when when you take a look at the email in the
sent items folder the "TO" field is empty. There is no way to see who the
receiver is.

Outlook get the recipient address from the code.

Any idea why this is happening?

Regards
Stefan
 
G

Guest

Thanks but the samples does not use the DoCmd.SendObject method and I don't
want to change the code completely.

The email function has been working fine for several years but the problem
started when we upgraded some users to Outlook 2003. I would also like to
clarify that the email is sent to the correct recipient BUT you can not see
the recipients name or adress after the email has been sent when you look at
the email in the sent items folder (or print it).

/Stefan
 
G

Guest

Hi StefanK

I do use Outlook2003 and within my db I have created a seperate form to email.
Perhaps this wil suit your need. I do not face any kind of trouble for some
time using this script.
Good Luck
Greetings Harry

**** begin code ****
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
' Dim objOutlookReplyTo As Outlook.Recipients
Dim objOutlookAttach As Outlook.Attachment
StrBody = Me!EmailBody
strSubject = Me!EmailSubject
strAddressTO = Me!EmailAddressTO
strAddressCC = Me!EmailAddressCC
strBCC1 = "(e-mail address removed);"
strBCC2 = "(e-mail address removed)"
strAddressBCC = strBCC1 & strBCC2
strAddressReply = "yourAddress used by send on behalf"

On Error GoTo ErrorMsgs

'Stop procedure when e-mail has been marked as sent.
If Me!Emailsend = True Then
MsgBox "Mail has been sent already", vbInformation, "ERROR"
Exit Sub
End If

If Me!EmailUrgent = False Then strImportance = olImportanceNormal
If Me!EmailUrgent = True Then strImportance = olImportanceHigh
If IsNull(Me.EmailSubject.Value) = True Then
MsgBox "Het onderwerp is niet ingevuld", vbInformation, "ERROR"
Exit Sub
ElseIf IsNull(Me.EmailBody.Value) = True Then
MsgBox "Er is geen text geschreven", vbInformation, "ERROR"
Exit Sub
End If
If Me!Sender.Value = 1 Then
strSender = "your mail address1"
ElseIf Me!Sender.Value = 2 Then
strSender = "your mail address2"
Else
MsgBox "No sender selected", vbInformation, "ERROR"
Exit Sub
End If

strRegards = vbCrLf & vbCrLf & "with kind regards,"
StrBody = StrBody & strRegards

'Save Record voor verzending
DoCmd.RunCommand acCmdSaveRecord

' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")
' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg
' adding strAddressTO.
' .To = (strAddressTO)
Set objOutlookRecip = .Recipients.Add(strAddressTO)
objOutlookRecip.Type = olTo
' Adding the CC en BCC recipient(s) to the message.
If Not IsNull(Me!EmailAddressCC) Then
Set objOutlookRecip = .Recipients.Add(strAddressCC)
objOutlookRecip.Type = olCC
End If
If IsNull(Me!EmailAddressBCC) Then
Set objOutlookRecip = .Recipients.Add(strAddressBCC)
objOutlookRecip.Type = olBCC
End If
' Set the Subject, Body, and Importance of the message".
If Not IsNull(Me!EmailBody) Then .Body = StrBody
If Not IsNull(Me!EmailSubject) Then .Subject = strSubject
' select importance high
.importance = strImportance
' select delivery receipt
.OriginatorDeliveryReportRequested = (Me.EmailDeliveryRequest.Value)
.ReadReceiptRequested = (Me.EmailReadRequest.Value)
' using the send on behalf
.SentOnBehalfOfName = "(e-mail address removed)"
'Instellen van de het reply adres.
.ReplyRecipients.Add (strAddressReply)

' below objOutlookMsg.Display means display the mail before sending,
' to avoid sending immediately the command send has to be disabled to
objOutlookMsg.Display

' 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
' If Not objOutlookRecip.Resolve Then
' objOutlookMsg.Display
' End If
' Next
' .Send

End With
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
Set objOutlookRecip = Nothing
Set objOutlookAttach = Nothing
Me!Emailsend = True
DoCmd.RunCommand acCmdSaveRecord
MsgBox "E-mail has been sent", vbInformation, "Header"

Exit Sub

ErrorMsgs:
If Err.Number = "287" Then

MsgBox "You clicked No to the Outlook security warning. " & _
"Rerun the procedure and click Yes to access e-mail " & _
"addresses to send your message. For more information, " & _
"see the document at http://www.microsoft.com/office" & _
"/previous/outlook/downloads/security.asp. "
Else
MsgBox Err.Number & " " & Err.Description
End If
End Sub
****end code****
 
G

Guest

Hi Harry,

Thanks but also your suggestion mean that I have to change method since I'm
using DoCmd.SendObject. My code includes creating a recordset and update
several tables after sending the email. I have used almost the same code in
several forms so I would prefer to keep on using DoCmd.SendObject.

There must be some difference in how Outlook2003 works with Access2002
compared to Outlook2002.
 
G

Guest

Hi Harry,

Just want to thankyou for posting that peice of code as i have spent a fair
amount of time trying to work out how to change who the receivers of the
email can automatically reply to.

Never thought of using .ReplyRecipients.Add ()

Your fantastic

Tanya
 
G

Guest

Hi Stefan,

I have found something that might work out, meaning using it I do see within
the sent Item to whom the mail was sent.
I do use a query to extract the e-mail addresses and use them for somekind
of direct mailing (sending invitations, etc).
Dim strEmailTo As Variant '(this is surely needed)
Dim rstRecords As Recordset
Dim srcMailTo As Variant
Dim srcMailTo2 As Variant
Dim What2Send As String

What2Send = "EmailAddresses" ' Name of query or table
srcMailTo = "[EmailAddress]" ' A key field
srcMailTo = "![EmailAddress]" ' A key field
Form4Send = your source form
Object2Send = Forms!YourMessageForm!cboObjects.Column(2) 'within my query
the third colomn contains the e-mail addresses

If MsgBox("Type your own story, 4) = 6 Then
'DoCmd.OpenForm "frmSending" ', , , , , acDialog
With rstRecords
Do Until .EOF
strEmailTo = "srcMailTo = '" & srcMailTo2 & " '" ' sets global
strEmailTo
DoCmd.SendObject What2Send, Forms!frmMessage!cboObjects.Column(0),
acFormatRTF, ![EmailAddress], , , rptSubject, rptMessageText, False, ""

.MoveNext ' Move to next record in Recordset
Loop
End With

'DoCmd.Close acForm, "frmSending", acSaveNo
MsgBox "Your E-mail has been sent !"
End If
----------------------------
As you see the part of the doCMD string ![EmailAddress] is providing the
needed.

However in return I have a question.
Do you know how to send the mail using a different account? I mean how to
use send of behalf.

Good Luck
Harry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top