attacher un element en vb.net via outlook
salut tous le monde.
je peux pas attacher des document txt ou doc ou xls quant je veux envoyé des email en vb.net via outlook
le programme m'a donnée ce message d'erreur :
http://tryimg.com/u/d3d25dedde.jpg
c'est mon code :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
| Try
Dim olApp As Outlook.Application
olApp = CreateObject("Outlook.Application")
Dim olNs As Outlook.NameSpace
olNs = olApp.GetNamespace("MAPI")
olNs.Logon()
Dim olItem As Outlook.ContactItem
olItem = olApp.CreateItem(Outlook.OlItemType.olContactItem)
With olItem
.FullName = "red_one"
.CompanyName = "my company"
.Email1Address = "red_one_hola@hotmail.com"
.JobTitle = "Developer"
End With
olItem.Save()
Dim olAppt As Outlook.AppointmentItem
olAppt = olApp.CreateItem(Outlook.OlItemType.olAppointmentItem)
olAppt.Start = Now()
Dim olMail As Outlook.MailItem
olMail = olApp.CreateItem(Outlook.OlItemType.olMailItem)
olMail.To = olItem.Email1Address
olMail.Subject = "test .........."
olMail.Body = "test pour attacher un element "
'Le problème dans ce code :
Dim att As String =Application.StartupPath + "\test.txt"
Dim at = New Attachment(att)
olMail.Attachments.Add(at, "txt", "", "test")
olMail.Send()
MsgBox(" Message a éte envoyé ", vbMsgBoxSetForeground)
olNs.Logoff()
olNs = Nothing
olMail = Nothing
olAppt = Nothing
olItem = Nothing
olApp = Nothing
Catch ex As Exception
MsgBox(ex.ToString)
End Try |
merci :)