IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C# Discussion :

Envoyer 2 emails par 'using System.Net.Mail' dans un formulaire en C# [Débutant]


Sujet :

C#

  1. #1
    Membre habitué
    Profil pro
    Inscrit en
    Avril 2010
    Messages
    316
    Détails du profil
    Informations personnelles :
    Localisation : Canada

    Informations forums :
    Inscription : Avril 2010
    Messages : 316
    Points : 155
    Points
    155
    Par défaut Envoyer 2 emails par 'using System.Net.Mail' dans un formulaire en C#
    Bonjour, j'ai un formulaire qui envoie 2 emails :

    1er au client, il s'agit d'un reçu :
    [MailAddress to = new MailAddress(t.MailNew);]
    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
    MailAddress from = new MailAddress(ConfigurationManager.AppSettings["FromCourriel"]);
    MailAddress to = new MailAddress(t.MailNew);
    MailMessage message = new MailMessage(from, to);
     
    message.Subject = "OBJET : Reçu";
    message.IsBodyHtml = true;
    message.Body = "<p>votre courriel a été envoyé, etc...</p>";
    message.BodyEncoding = System.Text.Encoding.UTF8;
     
    MailAddress bcc = new MailAddress(ConfigurationManager.AppSettings["copie_bbc"]);
    message.Bcc.Add(bcc);
     
    SmtpClient client = new SmtpClient();
    client.Host = ConfigurationManager.AppSettings["SmtpServerURL_"];
    client.Credentials = new System.Net.NetworkCredential("usernameHere", "passwordHere");
     
    Console.WriteLine("Sending an e-mail message to {0} by using the SMTP host {1}.",
    	 to.Address, message.CC.ToString(), message.Bcc.ToString());
     
    Console.WriteLine("Sending an e-mail message to {0} and {1}.",
    to.DisplayName, message.Bcc.ToString());
     
    try
    {
    	client.Send(message);
    }
    catch (Exception ex)
    {
    	Console.WriteLine("Exception caught in CreateBccTestMessage(): {0}",
    				ex.ToString());
    }
    2e c'est à nous, il s'agit d'une notification :
    [MailAddress mailNotificationNousTo = new MailAddress(ConfigurationManager.AppSettings["CourrielNotificationTO"]);]
    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
     MailAddress mailNotificationNousFrom = new MailAddress(ConfigurationManager.AppSettings["FromCourriel"]);
    MailAddress mailNotificationNousTo = new MailAddress(ConfigurationManager.AppSettings["CourrielNotificationTO"]);
    MailMessage mssgNotificationNous = new MailMessage(mailNotificationNousFrom, mailNotificationNousTo);
     
    message.Subject = "OBJET : Notification";
    message.IsBodyHtml = true; // pour interpreter le code html
    message.Body = "<p>Il y a une notification, etc</p>";
    message.BodyEncoding = System.Text.Encoding.UTF8;
     
    MailAddress bccc = new MailAddress(ConfigurationManager.AppSettings["notification_bbc"]);
    message.Bcc.Add(bccc);
     
    SmtpClient mssgNotificationNousClient = new SmtpClient();
    mssgNotificationNousClient.Host = ConfigurationManager.AppSettings["SmtpServerURL_"];
    client.Credentials = new System.Net.NetworkCredential("usernameHere", "passwordHere");
     
    Console.WriteLine("Sending an e-mail message to {0} by using the SMTP host {0}.", mailNotificationNousTo.Address);
     
    Console.WriteLine("Sending an e-mail message to {0} and {1}.", mailNotificationNousTo.DisplayName, message.Bcc.ToString());
    try
    {
    	mssgNotificationNousClient.Send(message);
    }
    catch (Exception ex)
    {
    	Console.WriteLine("Exception caught in CreateBccTestMessage(): {0}",
    				ex.ToString());
    }
    Nous ne recevons pas le courriel, mais le client reçois 2 courriels : celui du reçu et de la notification"
    comment je peux le corriger ?

    Merci

  2. #2
    Membre habitué
    Homme Profil pro
    Aprenti
    Inscrit en
    Mai 2015
    Messages
    199
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Canada

    Informations professionnelles :
    Activité : Aprenti

    Informations forums :
    Inscription : Mai 2015
    Messages : 199
    Points : 140
    Points
    140
    Par défaut
    Tu mélanges message

    il faudrait remplacer 'message' par 'mssgNotificationNous'

    voici le bon code pour 2e envoie
    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
    MailAddress mailNotificationNousFrom = new MailAddress(ConfigurationManager.AppSettings["FromCourriel"]);
    MailAddress mailNotificationNousTo = new MailAddress(ConfigurationManager.AppSettings["CourrielNotificationTO"]);
    MailMessage mssgNotificationNous = new MailMessage(mailNotificationNousFrom, mailNotificationNousTo);
     
    mssgNotificationNous.Subject = "OBJET : Notification";
    mssgNotificationNous.IsBodyHtml = true; // pour interpreter le code html
    mssgNotificationNous.Body = "<p>Il y a une notification, etc</p>";
    mssgNotificationNous.BodyEncoding = System.Text.Encoding.UTF8;
     
    MailAddress bccc = new MailAddress(ConfigurationManager.AppSettings["notification_bbc"]);
    mssgNotificationNous.Bcc.Add(bccc);
     
    SmtpClient mssgNotificationNousClient = new SmtpClient();
    mssgNotificationNousClient.Host = ConfigurationManager.AppSettings["SmtpServerURL_"];
    mssgNotificationNousClient.Credentials = new System.Net.NetworkCredential("usernameHere", "passwordHere");
     
    Console.WriteLine("Sending an e-mail message to {0} by using the SMTP host {0}.", mailNotificationNousTo.Address);
     
    Console.WriteLine("Sending an e-mail message to {0} and {1}.", mailNotificationNousTo.DisplayName, message.Bcc.ToString());
    try
    {
    	mssgNotificationNousClient.Send(mssgNotificationNous);
    }
    catch (Exception ex)
    {
    	Console.WriteLine("Exception caught in CreateBccTestMessage(): {0}",
    				ex.ToString());
    }

  3. #3
    Membre habitué
    Profil pro
    Inscrit en
    Avril 2010
    Messages
    316
    Détails du profil
    Informations personnelles :
    Localisation : Canada

    Informations forums :
    Inscription : Avril 2010
    Messages : 316
    Points : 155
    Points
    155
    Par défaut
    Super tonton,

    merci, ça marche

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. smtp envoi de mail par System.net.mail
    Par batou22003 dans le forum VB.NET
    Réponses: 7
    Dernier message: 01/02/2011, 17h11
  2. Envoie d'email avec system.net.mail
    Par urbanspike dans le forum VB.NET
    Réponses: 2
    Dernier message: 24/06/2009, 08h53
  3. Réponses: 17
    Dernier message: 09/05/2009, 21h54
  4. [Mail] Envoyer un email par une interface Web
    Par stephane81 dans le forum Langage
    Réponses: 1
    Dernier message: 12/12/2007, 17h43
  5. [ASP.Net] System. Net. Mail
    Par beowax dans le forum ASP.NET
    Réponses: 3
    Dernier message: 27/10/2006, 09h05

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo