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();
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...