Salut tout le monde !!!
Je débute en C# et je souhaite envoyer un mail via outlook avec une application que j'ai créé.
Pour cela j'ai suivi ce tuto :
Tuto
le problème c'est que j'ai cette erreur :
Voici mon code :L'exception System.Runtime.InteropServices.COMException n'a pas été gérée
Message=Opération abandonnée (Exception de HRESULT : 0x80004004 (E_ABORT))
Source=""
ErrorCode=-2147467260
...
L'erreur apparait sur cette ligne :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using OutLook = Microsoft.Office.Interop.Outlook; namespace Connectoutlook { public partial class Form2 : Form { public Form2() { InitializeComponent(); } private void envoimail_Click(object sender, EventArgs e) { Microsoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application(); OutLook.MailItem mail = (OutLook.MailItem)app.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem); mail.Recipients.Add(this.emaildestinataire.Text); mail.Subject = String.Format(this.objetmail.Text); mail.Body = String.Format(this.contenumail.Text,objetmail.Text, Environment.NewLine); // mail.Attachments.Add(textBox3.Text, Outlook.OlAttachmentType.olByValue, 1, String.Concat("Facture ", this.textBox2.Text)); mail.BodyFormat = Microsoft.Office.Interop.Outlook.OlBodyFormat.olFormatHTML; mail.Display(false); // Envoi du mail ((OutLook._MailItem)mail).Send(); MessageBox.Show("Mail envoyé !! "); } } }
Merci d'avance à tous !!!!
Code : Sélectionner tout - Visualiser dans une fenêtre à part mail.Recipients.Add(this.emaildestinataire.Text);
Partager