attachments get mangled when sending via MAPI

P

Peter Schram

I have built a vba program in Access that will send mails with word
documents. Some of the persons on the receiving-end are not able to
read the attachments. Some have an attachment with names like
ATT12345.ATT, others wordfile.doc.dat. Some can't even save or open the
files.

When using Outlook to send identical messages, they are received ok. I
set up the options of outlook to use plain-text messages and Western
European (ISO) encoding. However the encoding of the attachment seems
to differ between a manual send and automatic send.

I use the following code to send the mails, which works ok:

Dim objSession As MAPI.Session
Dim objNewMessage As MAPI.message
Dim objAttach As MAPI.Attachment
Dim objRecipient As MAPI.Recipient

' Create MAPI session
Set objSession = CreateObject("MAPI.Session")

'Logon using an existing MAPI profile with a new session
objSession.Logon showDialog:=False, ProfileInfo:="exchange-server
address" & vbLf & "account"

' Create a new message
Set objNewMessage = objSession.Outbox.Messages.Add

'edit the message to fit our needs
With objNewMessage ' message object
.Subject = varsubject
.Text = Varbody
Set objAttach = .Attachments.Add ' add the attachment
With objAttach
.Type = CdoFileData
.Position = 0 ' render at first character of message
.Name = MyfileName
.ReadFromFile varattach
End With
.Update ' update message to save attachment in MAPI system
End With

' Add recipient and resolve against the directory
Set objRecipient = objNewMessage.Recipients.Add
objRecipient.Name = varrecip
objRecipient.Resolve

' Send message
objNewMessage.Update
objNewMessage.Send

' Logoff from MAPI Session
objSession.Logoff

Is the anybody who can point me in the right direction to tackle this
problem. I need to find a way to get identical encoding on the
attachment when using the automatic way.

Thanks in advance,

Petetr Schram
 
D

Davidg

I am having the same problem. Also, is there a way to specify the from
field?

I have tried
..From = (e-mail address removed)
and
..SenderName
I think that one is tied to the account that is logged in to outlook. I
would like the message to be sent with out the user input. (automated)

Thanks in advance
 
P

Peter Schram

I have found the solution for my email problem. It is necessary to fill
the source property of the attachment object.

The codepart must be altered like so:

With objAttach
.Type = CdoFileData
'new line!!!!
.Source = varattach
.Position = 0 ' render at first character of message
.Name = MyfileName
.ReadFromFile varattach
End With
 

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