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
| private void button3_Click(object sender, EventArgs e)
{
// Contrôle sur l'objet
//~~~~~~~~~~~~~~~~~~~~~~
if (txtSubject.Text.Length == 0) { MessageBox.Show("Please enter all the required details."); return; };
// Contrôle sur les destinateurs
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if (lstTo.Items.Count == 0) { MessageBox.Show("First add the recepients to whome the mail has to be sent."); return; }
// Contrôle sur le contenu du message
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if (txtrichBody.Text.Equals(""))
{
DialogResult DR = MessageBox.Show("The body of the mail has been left blank. Are you sure to send the mail any way!", "Invalid Message", MessageBoxButtons.YesNo);
if (DR == DialogResult.No) return;
}
// Envoi du mail
//~~~~~~~~~~~~~~
try
{
EmailMessage message = new EmailMessage(ConnexionEws.getInstance.ExchangeService());
message.Subject = txtSubject.Text;
string test = txtrichBody.Text;
message.Body = test;
for (int i = 0; i < lstTo.Items.Count; i++)
{
message.ToRecipients.Add(lstTo.Items[i].ToString());
}
message.SendAndSaveCopy();
}
catch (Exception ErrSend)
{
MessageBox.Show(ErrSend.Message, "Erreur");
return;
}
MessageBox.Show("Message envoyé", "Info");
} |
Partager