Envoyer un E-mail simplement
Bonjour les amis ;
je travaille sous C#, j'aimerais développer une petite application Form qui servira à envoyer un / plusieur E-mail, j'utilise une communication SMPT, voici mon peti code comment j'ai procédé :
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 46 47 48 49 50
| using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net.Mail;
namespace testMail2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnEnvoyer_Click(object sender, EventArgs e)
{
try
{
// To
MailMessage mailMsg = new MailMessage();
mailMsg.To.Add("megaguerrier@hotmail.fr");
// From
MailAddress mailAddress = new MailAddress("soufian1364@hotmail.com");
mailMsg.From = mailAddress;
// Subject and Body
mailMsg.Subject = "salutation";
mailMsg.Body = "Hellow Word";
// Init SmtpClient and send
SmtpClient smtpClient = new SmtpClient("localhost", 25); // 25 : port utilisé par Outlook
System.Net.NetworkCredential credentials = new System.Net.NetworkCredential("compte", "mot de passe");
smtpClient.Credentials = credentials;
smtpClient.Send(mailMsg);
MessageBox.Show("ca y est Message envoyé");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
} |
Problème :
Ce programme s'exécute sans erreur de complilation, mais il lance le catch--> MessageBox : "Echec d'envoi de courrier".
les deux lignes que je suspecte avec certitude sont :
Code:
1 2
| SmtpClient smtpClient = new SmtpClient("localhost", 25); // 25 : port utilisé par Outlook
System.Net.NetworkCredential credentials = new System.Net.NetworkCredential("compte", "mot de passe"); |
Sûrement y a un problème dans ce que j'ai mis comme paramètres dans new SmtpClient("localhost", 25); et dans la ligne suivante.
So, please try to right to me. I need to your help.
____________________________________________
Rien n'est impossible, il suffit de savoir comment !