Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1683 connectés 

  FORUM HardWare.fr
  Programmation
  VB/VBA/VBS

  Programmation E-Mail Automatique

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

Programmation E-Mail Automatique

n°2063560
kivis
Posté le 15-03-2011 à 12:13:33  profilanswer
 

Bonjour à tous ,
 
Je suis nouveau sur le forum , je viens sur le forum pour trouver une idée de développement pour ma société.  
Nous avons la problématique suivante :
1. Nous envoyons des mails à une autre société de manière hebdomadaire, il y a 1000 contrats à envoyer en format PDF.  
2. La société en question souhaite recevoir chaqu'un des contrats sous la forme 1 PDF de 3 pages envoyé par mail avec à chaque fois dans l'objet le nom du client.  
 
Donc, imaginez scanner 1000 contrats ( de 3 pages ) pour en faire à chaque fois un pdf qu'on doit renomer puis envoyer par mail avec le nom du fichier qui correspond  
au nom du client .... C'est à devenir fou.  
 
Mon idée : Réaliser un petit soft qui permetrait de recuperer un PDF de copier coller le nom du PDF dans l'objet du mail ... Mais est ce possible ?  
 
Ma question est : Que puis faire pour améliorer ce processus avec un outil informatique ( sarbacane etc... ), ou est ce que je dois me lancer dans de la programmation ?  
Est il possible de réaliser un tel programme , j'ai de bonnes connaissances en VB.  
 
Merci pour vos idées elles sont toutes la bienvenue.

mood
Publicité
Posté le 15-03-2011 à 12:13:33  profilanswer
 

n°2063604
kiki29
Posté le 15-03-2011 à 13:55:51  profilanswer
 

Salut,voir pour cela http://access.developpez.com/faq/?page=Outlook et http://excel.developpez.com/faq/?page=Messagerie et particulierement CDO


Message édité par kiki29 le 15-03-2011 à 13:57:39
n°2063989
hazzelthor​n
Payday vador
Posté le 16-03-2011 à 11:11:04  profilanswer
 

j'ai realisé une application d'envoi massif de mail avec le body du mail personnalise en fonction du client si tu veux je peux t'envoyer mes sources :)  et en piece jointe le pdf associe a la societe :)

 

c'est du VB.net :)

 

EDIT : le body du mail correspond a un template html lu par l'appli et les motifs qu'il trouvent sont remplacer par des valeurs que j'vais chercher dans une BDD, en l'occurrence SQL server 2005


Message édité par hazzelthorn le 16-03-2011 à 11:12:28
n°2064065
boomy29
PSN: tintine29
Posté le 16-03-2011 à 14:00:12  profilanswer
 

moi ça m’intéresse pas mal tes sources en tout cas :D

n°2064094
hazzelthor​n
Payday vador
Posté le 16-03-2011 à 14:32:46  profilanswer
 

ben envoie moi un PM et je t'envoies les sources sur ton mail, l'application possèdent une interface :)  
 
je vais linker a quoi elle ressemble ainsi que son fonctionnement :)  
 
EDIT : dans quelques minutes :)
 
 
Voilà le module :  
 

Code :
  1. Imports System.Threading
  2. Imports System.Net.Mail
  3. Imports System.Text.RegularExpressions
  4. Imports System.Data.SqlClient
  5. Imports System
  6. Imports System.IO
  7. Imports System.Windows.Forms
  8. Imports Microsoft.VisualBasic
  9. Imports System.Drawing
  10. Module Module1
  11.     Dim con_strg As String = System.Configuration.ConfigurationSettings.AppSettings("conSQL" )
  12.     Sub ChargeTable(ByVal RqtCtc As String, ByVal TableName As String, ByVal DatasetCtc As System.Data.DataSet)
  13.         Dim con As New SqlConnection()
  14.         Dim sqlda As SqlDataAdapter
  15.         con = New SqlConnection(con_strg)
  16.         con.Open()
  17.         sqlda = New SqlDataAdapter(RqtCtc, con)
  18.         Try
  19.             ' Récupération des données dans une table nomtable
  20.             sqlda.Fill(DatasetCtc, TableName)
  21.         Catch ex As Exception
  22.             MsgBox(ex.ToString)
  23.         Finally
  24.             con.Close()
  25.         End Try
  26.     End Sub
  27.     Function lire_replace_html(ByVal fichier As String, ByVal position As String) As ArrayList
  28.         Dim civil As String = System.Configuration.ConfigurationSettings.AppSettings("Civilite" )
  29.         Dim version As String = System.Configuration.ConfigurationSettings.AppSettings("Version" )
  30.         Dim RespCompte As String = System.Configuration.ConfigurationSettings.AppSettings("ResponsableCompte" )
  31.         Dim DataMail As New Data.DataSet()
  32.         Dim requete As String = System.Configuration.ConfigurationSettings.AppSettings("Rqt1" )
  33.         Try
  34.             ChargeTable(requete, "RECHERCHE", DataMail)
  35.         Catch ex As Exception
  36.             MsgBox(ex.ToString)
  37.         End Try
  38.      
  39.         'Ici on compte le nombre de lignes et de colonnes du datatable
  40.         Dim maligne As String
  41.         Dim monlecteur As StreamReader
  42.         Dim meslignes As New ArrayList
  43.         Dim template As Regex = New Regex(civil)
  44.         Dim template2 As Regex = New Regex(version)
  45.         Dim template3 As Regex = New Regex(RespCompte)
  46.         Try
  47.             monlecteur = New StreamReader(fichier)
  48.             With monlecteur
  49.                 .BaseStream.Seek(0, SeekOrigin.Begin)
  50.                 While (.Peek >= 0)
  51.                     maligne = .ReadLine.ToString()
  52.                     'test si il y a le motif civilite dans ma ligne lue
  53.                     If InStr(maligne, civil) <> 0 Then
  54.                         meslignes.Add(Regex.Replace(maligne, civil, Civilite(meslignes, DataMail, position)))
  55.                         'test s'il y a le motif version dans ma ligne lue
  56.                     ElseIf InStr(maligne, version) <> 0 Then
  57.                         meslignes.Add(Regex.Replace(maligne, version, System.Configuration.ConfigurationSettings.AppSettings("Numero" )))
  58.                         'test s'il y a le motif responsablecompte dans ma ligne lue
  59.                     ElseIf InStr(maligne, RespCompte) <> 0 Then
  60.                         'si le champ type client de mon datasetmail ne contient pas 'toto' ou 'Autre Client' alors j'affiche le responsable de compte associé
  61.                         If (DataMail.Tables("RECHERCHE" ).Rows(position).Item(6).ToString <> "Autre client" And DataMail.Tables("RECHERCHE" ).Rows(position).Item(6).ToString <> "toto" ) Then
  62.                             meslignes.Add(Regex.Replace(maligne, RespCompte, ResponsableCompte(meslignes, DataMail, position)))
  63.                             'sinon j'affiche toto tutu
  64.                         Else
  65.                             meslignes.Add(Regex.Replace(maligne, RespCompte, ("Responsable Client <a href=mailto:toto@titi.com>toto tutu</a>" )))
  66.                         End If
  67.                         'si aucun des test n'est rempli je recopie ma ligne lu en cours dans mon body de mail
  68.                         Else
  69.                             meslignes.Add(maligne)
  70.                         End If
  71.                 End While
  72.             End With
  73.         Catch ex As Exception
  74.             Console.WriteLine(ex.Message)
  75.         Finally
  76.             monlecteur.Close()
  77.         End Try
  78.         Return meslignes
  79.     End Function
  80.     Function Civilite(ByVal meslignes As ArrayList, ByVal DatasetMail As DataSet, ByVal pos_dataset As Integer) As String
  81.         Dim motif As String
  82.         Dim genre As String
  83.         If DatasetMail.Tables("RECHERCHE" ).Rows(pos_dataset).Item(0) = "Monsieur" Then
  84.             genre = "Cher"
  85.         Else
  86.             genre = "Chère"
  87.         End If
  88.         motif = genre + " " + DatasetMail.Tables("RECHERCHE" ).Rows(pos_dataset).Item(1) + " " + DatasetMail.Tables("RECHERCHE" ).Rows(pos_dataset).Item(2)
  89.         Return motif
  90.     End Function
  91.     Function Array2String(ByVal meslignes As ArrayList) As String
  92.         Dim x As Integer
  93.         Array2String = ""
  94.         For x = 0 To meslignes.Count - 1
  95.             Array2String += meslignes.Item(x).ToString
  96.         Next
  97.         Return Array2String
  98.     End Function
  99.     Function ResponsableCompte(ByVal meslignes As ArrayList, ByVal DatasetMail As DataSet, ByVal pos_dataset As Integer) As String
  100.         Dim toto As Array = Split(DatasetMail.Tables("RECHERCHE" ).Rows(pos_dataset).Item(5), "," )
  101.         Dim nom As String = toto(0)
  102.         Dim prenom As String = toto(1)
  103. 'Requete 2 sert a selectionner les responsable de compte associé aux clients
  104.         Dim requete2 As String = ""
  105.         Dim DataResp As New Data.DataSet()
  106.         Dim mailResp As String
  107.         Try
  108.             ChargeTable(requete2, "RECHERCHE", DataResp)
  109.         Catch ex As Exception
  110.             MsgBox(ex.ToString)
  111.         End Try
  112.         mailResp = "Responsable de Compte <a href=" + "mailto:" + DataResp.Tables("RECHERCHE" ).Rows(0).Item(0).ToString + ">" + DataResp.Tables("RECHERCHE" ).Rows(0).Item(2).ToString + " " + DataResp.Tables("RECHERCHE" ).Rows(0).Item(1).ToString + "</a> pour envisager une migration"
  113.         Return mailResp
  114.     End Function
  115.     Function EmailValide(ByVal mail_address As String) As Boolean
  116.         Dim rexp As New Regex("^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$", RegexOptions.IgnoreCase)
  117.         Return rexp.IsMatch(mail_address)
  118.     End Function
  119. End Module


 
 
 
Mon form
 

Code :
  1. Imports System.Threading
  2. Imports System.Net.Mail
  3. Imports System.Text.RegularExpressions
  4. Imports System.Data.SqlClient
  5. Imports System.DBNull
  6. Imports System
  7. Imports System.IO
  8. Imports System.Windows.Forms
  9. Imports Microsoft.VisualBasic
  10. Imports System.Drawing
  11. Public Class Kimoce2mailing
  12.     Public Sub liste_contact_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles liste_contact.Click
  13.         Dim DataMail As New Data.DataSet()
  14.         Dim requete As String = System.Configuration.ConfigurationSettings.AppSettings("Rqt1" )
  15.         Try
  16.             ChargeTable(requete, "RECHERCHE", DataMail)
  17.         Catch ex As Exception
  18.             MsgBox(ex.ToString)
  19.         End Try
  20.         'Ici on compte le nombre de lignes et de colonnes du datatable
  21.         Dim NbRow As Integer = 0
  22.         Dim nbcol As Integer = DataMail.Tables("RECHERCHE" ).Columns.Count
  23.         NbRow = DataMail.Tables("RECHERCHE" ).Rows.Count
  24.         Dim adresse_mail As String
  25.         Dim fichier As String
  26.         Dim x As Integer
  27.         If option1.Checked = True Then
  28.             TextBox1.Clear()
  29.             fichier = System.Configuration.ConfigurationSettings.AppSettings("CheminFichierMajeur" )
  30.         ElseIf option2.Checked = True Then
  31.             TextBox1.Clear()
  32.             fichier = System.Configuration.ConfigurationSettings.AppSettings("CheminFichierBuild" )
  33.         End If
  34.         TextBox1.AppendText(Environment.NewLine + "Début envoi des mails" + Environment.NewLine)
  35.        
  36.         Dim smtp As New SmtpClient(System.Configuration.ConfigurationSettings.AppSettings("Serveur" ))
  37.         pbar.Visible = True
  38.         pbar.Minimum = 1
  39.         pbar.Value = 1
  40.         pbar.Maximum = NbRow
  41.         pbar.Step = 1
  42.         For x = 0 To NbRow - 1
  43.             Dim mail As New MailMessage()
  44.             adresse_mail = (DataMail.Tables("RECHERCHE" ).Rows(x).Item(4))
  45.             If EmailValide(adresse_mail) = True Then
  46.                 TextBox1.AppendText(Environment.NewLine + "Envoi du mail à " + DataMail.Tables("RECHERCHE" ).Rows(x).Item(2) + " " + DataMail.Tables("RECHERCHE" ).Rows(x).Item(1) + Environment.NewLine)
  47.                 mail.From = New MailAddress(System.Configuration.ConfigurationSettings.AppSettings("AddrFrom" ))
  48.                 mail.To.Add(DataMail.Tables("RECHERCHE" ).Rows(x).Item(4))
  49.                 mail.Bcc.Add(System.Configuration.ConfigurationSettings.AppSettings("AddrCache" ))
  50.                 'set the content
  51.                 If option1.Checked = True Then
  52.                     mail.Subject = System.Configuration.ConfigurationSettings.AppSettings("SujetMajeur" )
  53.                 ElseIf option2.Checked = True Then
  54.                     mail.Subject = System.Configuration.ConfigurationSettings.AppSettings("SujetBuild" )
  55.                 End If
  56.                 mail.Body = Array2String(lire_replace_html(fichier, x))
  57.                 mail.IsBodyHtml = True
  58.                 'add an attachment from the filesystem
  59.                 mail.Attachments.Add(New Attachment(System.Configuration.ConfigurationSettings.AppSettings("PieceJointe" )))
  60.                 'envoi du message
  61.                 smtp.Send(mail)
  62.             End If
  63.             mail = Nothing
  64.             pbar.PerformStep()
  65.         Next
  66.         TextBox1.AppendText(Environment.NewLine + "Fin envoi des mails" + Environment.NewLine)
  67.         Dim mailtrace As New MailMessage()
  68.         Dim erreur As String
  69.         mailtrace.From = New MailAddress(System.Configuration.ConfigurationSettings.AppSettings("AddrFrom" ))
  70.         mailtrace.To.Add(New MailAddress(System.Configuration.ConfigurationSettings.AppSettings("AddrDestTrace" )))
  71.         mailtrace.Subject = "Liste des adresses mails non conforme"
  72.         For x = 0 To NbRow - 1
  73.             adresse_mail = (DataMail.Tables("RECHERCHE" ).Rows(x).Item(4))
  74.             If EmailValide(adresse_mail) = False Then
  75.                 erreur = erreur + DataMail.Tables("RECHERCHE" ).Rows(x).Item(3) + " || " + DataMail.Tables("RECHERCHE" ).Rows(x).Item(2) + " || " + DataMail.Tables("RECHERCHE" ).Rows(x).Item(1) + " || " + DataMail.Tables("RECHERCHE" ).Rows(x).Item(4) + "<br>"
  76.             End If
  77.         Next
  78.         mailtrace.IsBodyHtml = True
  79.         If erreur = "" Then
  80.             mailtrace.Body = "Toutes les adresses mails sont conformes."
  81.         Else
  82.             mailtrace.Body = "Société" + " || " + "Nom" + " || " + "Prénom" + " || " + "Adresse mail" + "<br><br>" + erreur
  83.         End If
  84.         smtp.Send(mailtrace)
  85.         mailtrace = Nothing
  86.     End Sub
  87.     Private Sub QuitterToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles QuitterToolStripMenuItem.Click
  88.         Me.Dispose()
  89.     End Sub
  90. End Class


 
 
 
 
 
Le fichier de config associé :  
 

Code :
  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <configuration>
  3.   <appSettings>
  4.     <!-- REQUETES        Pour selectionner les clients  Pour marquer le signe différent dans la requête SQL utiliser != et pas <> sinon le logiciel ne reconnait pas la requête-->
  5.     <add key="Rqt1" value=","/>
  6.     <!--MAIL-->
  7.     <add key="AddrFrom" value="" />
  8.     <add key="AddrCache" value="" />
  9.     <add key="SujetBuild" value="" />
  10.     <add key="SujetMajeur" value=" />
  11.     <add key="Serveur" value="" />
  12.     <add key="AddrDestTrace" value="" />
  13.     <!--CIVILITE-->
  14.     <add key="Civilite" value ="{civilite}"/>
  15.     <!--SQL-->
  16.     <add key="conSQL" value ="Data Source=toto;Initial catalog=titi;Integrated Security=SSPI"/>
  17.     <!--RESPONSABLE COMPTE-->
  18.     <add key="ResponsableCompte" value="{RC}"/>
  19.     <!--version-->
  20.     <add key="Version" value ="{version}"/>
  21.      <add key="Numero" value =""/>
  22.     <!--FICHIER HTML-->
  23.     <add key="CheminFichierMajeur" value ="C:\build_majeur.html"/>
  24.     <add key="CheminFichierBuild" value ="C:\build_trimestriel.html"/>
  25.     <!--FICHIER JOINT-->
  26.     <add key="PieceJointe" value ="C:\Documents and Settings\toto.pdf"/>
  27.   </appSettings>
  28. </configuration>


 
 
le template HTML qui va bien pour chercher les motifs :  
 

Code :
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" >
  3.    <head>
  4.        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  5.    </head>
  6.    {civilite}
  7.    <br><br>
  8.    Vous &ecirc;tes utilisateur de la solution toto et nous vous en remercions.
  9. <br><br>
  10. Nous avons le plaisir de vous informer que la version {version} de toto est d&eacute;sormais disponible.
  11. <br><br>
  12. A cet effet, nous vous adressons  ci-joint  la &#139;&#139; release &#155;&#155; note associ&eacute;e  dans laquelle vous trouverez
  13. notamment la liste d&eacute;taill&eacute;e des nouvelles fonctionalit&eacute;s mises  &agrave; votre disposition.
  14. <br>
  15. <br>
  16. Afin de b&eacute;n&eacute;ficier de tous les apports de cette nouvelle version majeure, nous vous invitons &agrave; contacter votre {RC}
  17. <br><br>
  18. Nous esp&eacute;rons que ces nouvelles fonctionnalit&eacute;s vous satisferont et restons bien &eacute;videmment &agrave; votre enti&egrave;re disposition.
  19. <br>
  20. <br>
  21. Vous remerciant de votre confiance,
  22. <br>
  23. <br>
  24. Cordialement,
  25. <br> <br>
  26. Votre service client.
  27.    <body>
  28.    </body>
  29. </html>


Message édité par hazzelthorn le 16-03-2011 à 15:05:00
n°2064356
kivis
Posté le 17-03-2011 à 09:47:26  profilanswer
 

Merci pour le script !!

n°2064409
boomy29
PSN: tintine29
Posté le 17-03-2011 à 13:40:31  profilanswer
 

ouai c'est cool  
maintenant j’espère pouvoir le tester  
car ça m'intrigue pas mal


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  VB/VBA/VBS

  Programmation E-Mail Automatique

 

Sujets relatifs
Probème d'accent dans le sujet de mail PHPmailer daemon, mail undelivered
Ajout de pièce jointe dans un mailcopier lignes excel et coller dans corps de mail outlook (VBA)
Ecriture automatiqueProgrammation sur automate
[Projet] Notifieur de mail USB adapté à Thunderbirdbon de commande a envoyer vers mon adresse mail
Insérer logo dans mailProgrammation en C, besoin d'aide
Plus de sujets relatifs à : Programmation E-Mail Automatique


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR