Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Does anyone know how to attach file in outlook automation?

1 view
Skip to first unread message

Alex Ng

unread,
Dec 21, 2002, 12:53:44 AM12/21/02
to
Does Anone know how to Attach file to Outlook Email Message?

I am using outlook automation to send email and I need to attach file to
message. Does any one know how to attach file?

Here is my code but attaching part is missing. Can anyone help?

_Application da;
if(!da.CreateDispatch("Outlook.Application.9"))
AfxMessageBox("CreateDispatch failed.", MB_OK | MB_SETFOREGROUND);
_MailItem myMail;
myMail=da.CreateItem(0);
myMail.SetTo("em...@email.com");
myMail.SetBody("Message");

/// Please tell me how to add attachment "D:\\File.txt"

myMail.Save();


Lars Van Jeurissen

unread,
Dec 28, 2002, 10:50:01 PM12/28/02
to
Look in the MSDN under Microsoft Office (General)
I will Add an snippet from the document. The code is in VB but the idea is
clear. You have to get the da.Attachment. I don't have the outlook includes
but I expect something like.
I could sent you the document at your email address, but you probably can
find it on the net.

Nizchka niz...@hotmail.com

_Application da;
_Attachment am;


if(!da.CreateDispatch("Outlook.Application.9"))
AfxMessageBox("CreateDispatch failed.", MB_OK | MB_SETFOREGROUND);
_MailItem myMail;
myMail=da.CreateItem(0);

am = myMail.Attachment;


myMail.SetTo("em...@email.com");
myMail.SetBody("Message");

am.Add("D:\\File.txt");

/// Please tell me how to add attachment "D:\\File.txt"

myMail.Save();

-- vbcode --

Sub NewMailMessage()
Dim ol As New Outlook.Application
Dim ns As Outlook.NameSpace
Dim newMail As Outlook.MailItem

'Return a reference to the MAPI layer.
Set ns = ol.GetNamespace("MAPI")

'Create a new mail message item.
Set newMail = ol.CreateItem(olMailItem)
With newMail
'Add the subject of the mail message.
.Subject = "Training Information for October 1997"
'Create some body text.
.Body = "Here is the training information you requested:" & vbCrLf

'Add a recipient and test to make sure that the
'address is valid using the Resolve method.
With .Recipients.Add("min...@imginc.com")
.Type = olTo
If Not .Resolve Then
MsgBox "Unable to resolve address.", vbInformation
Exit Sub
End If
End With

'Attach a file as a link with an icon.
With .Attachments.Add _
("\\Training\training.xls", olByReference)
.DisplayName = "Training info"
End With

'Send the mail message.
.Send
End With

'Release memory.
Set ol = Nothing
Set ns = Nothing
Set newMail = Nothing
End Sub


"Alex Ng" <alex...@netvigator.com> schreef in bericht
news:atv724$av...@imsp212.netvigator.com...

0 new messages