PDA

Click to See Complete Forum and Search --> : Sending e-mails from Access using Outlook [resolved]


Oliver1
Feb 1st, 2005, 06:27 AM
Hi this is a problem which I'm realy stuck on. For a bit of background we use Exchange 2003 as are mailserver and have outlook 2000 clients.
I have an e-mailer program which takes an e-mail it recives and forward it out again. The problem is we have a client complaing saying he only wants the e-mail we send him to be in plain text. If I send the program straight from Outlook it's fine, but for some reson when I use the below code to send an e-mail it's sent as both plain text and HTML, anyone now how to change this.


Private Function sendemail(todest As String, subject As String, body As String) As Boolean
On Error GoTo sendwarning:
Dim fnam As String
Dim loopcounter As Integer
loopcounter = 0

Set objMailitem = objApp.CreateItem(olMailItem)
If addatt Then
Set myatts = myitem.Attachments
If myatts.Count > 0 Then
Set myatts = myitem.Attachments
Set objattachments = objMailitem.Attachments

Do While loopcounter < myatts.Count
loopcounter = loopcounter + 1
Set myatt = myatts(loopcounter)
fnam = myatt.FileName
If Mid(fnam, 1, 4) = "Page" Then
fnam = Mid(fnam, 1, 11)
End If
myatt.SaveAsFile fnam

objattachments.Add (fnam)

Loop

Else
Set myatt = Nothing
End If
End If
objMailitem.To = todest
objMailitem.subject = subject
objMailitem.body = body
objMailitem.Send
sendemail = True
Exit Function

sendwarning:
sendemail = False

End Function

Dave Sell
Feb 1st, 2005, 09:50 AM
Cross ref: http://www.vbforums.com/showthread.php?t=321160&highlight=objMailItem

As per MSDN: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cdo/html/_denali_bodyformat_property_cdonts_newmail_object_.asp

Change the .BodyFormat to 1.

Oliver1
Feb 1st, 2005, 09:54 AM
Thanks, is annoying when you can't figure something out. Should have done a search first (bad me) but didn't think it would be the kind of problm anyone else would have.

Thanks again

Dave Sell
Feb 1st, 2005, 09:55 AM
No, it's not your fault. The Office ActiveX EXE objects are extremely poorly documented. You have to dig hard and long to get any info on the internals of these objects.

RobDog888
Feb 1st, 2005, 10:51 AM
Dave, instead of setting it to 1, wouldnt it be easier reading to set it to the const. - olFormatHTML ?

Dave Sell
Feb 1st, 2005, 10:52 AM
Dave, instead of setting it to 1, wouldnt it be easier reading to set it to the const. - olFormatHTML ?
Totally. But sometimes you don't get constants in VB, and I couldn't tell by the MSDN documentation so I just played it safe. Definately use constants if they are available to you.

RobDog888
Feb 1st, 2005, 11:08 AM
Thats what I thought. :thumb: You dont get the const.'s when you are using
VBScript or are using late binding ;)

Dave Sell
Feb 1st, 2005, 11:12 AM
P.S. the MSDN docs say to use CdoBodyFormatText. I think its different in the VB IDE.

RobDog888
Feb 1st, 2005, 11:16 AM
Depends on how his module code is. If he has a reference to Outlook added
then use the olFormatHTML. If not then its Access' CDO default reference, I
think is how it is?

Dave Sell
Feb 1st, 2005, 11:18 AM
ahem * cough * ahem - he wants plain text... :bigyello:

RobDog888
Feb 1st, 2005, 11:21 AM
Doh! Thats right. olFormatPlain it is then. :blush: