Corps d'email depuis un fichier texte en VB ?

Résolu/Fermé
manautop Messages postés 138 Date d'inscription lundi 27 novembre 2006 Statut Membre Dernière intervention 24 janvier 2013 - Modifié par manautop le 23/01/2012 à 18:12
manautop Messages postés 138 Date d'inscription lundi 27 novembre 2006 Statut Membre Dernière intervention 24 janvier 2013 - 25 janv. 2012 à 15:20
Bonjour,

je dévellope un petit programme pour mon assoc qui me permet de récuperer les info tapées dans une form1 contenant des :

- des combobox
- des datepickerbox
- des textbox
- des richtextbox

dans un premier temps la marco verfie qu'il s'agit bien de chiffre dans une textbox
puis elle devrait copier chaque information dans un fichier texte, une info par ligne (ex : debut de date de promotion : 'valeur choisie dants la satepickerbox pour la ligne 1 etc )

Ensuite elle devrait pouvoir envoyer l'info sur mon mail directement en copiant les infos de ce fichier texte dans le corp de mon mail.

mes problèmes sont les suivant (en gras dans le code):

--- en premier lieu la création du fichier texte pose problème mais je ne comprend pas pourquoi
---- en second lieu je n'arrive pas à copier coller le fichier texte dans le corp de l'email envoyé et ceux après beaucoup de recherche sur internet et de test.


j'arrive parfaitement à m'envoyer l email sans ouvrir outlook par l'integration des references Microsoft.outlook.12.0.object.library



voici le code


Public Class Form1



Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.Close()

End Sub

Private Sub Nombre()
'__________________________________________________________________
' Vérifie si la valeur entrée est numérique dans Costtextbox
If Not IsNumeric(CostTextBox.Text) Then
MsgBox("Please enter a number in the Cost Estimation")
Stop
End If
End Sub


Private Sub Formulaire()
' ______________________________________________________________________
' création d'un fichier texte

Dim f As Integer
Dim FileName As String

FileName = "c:\DemandeCodePromo.txt"

' Obtention d'un numéro de fichier libre
f = FreeFile()

' Ouverture en mode écriture ("output")
open "c:\DemandeCodePromo.txt" for output as #f


' Ecriture de lignes
Print #f, "PROMOTION REQUEST CODE :"
'espace

print #f, "Type Of Promotion : " & TypeOfPromoCombo.Text
print #f, "Start Date Promotion :" & StartDateTimePicker.Text
print #f, "End Date Promotion :" & EndDateTimePicker.Text
print #f, "End Date Bonus 1st Stay :" & EndBonusDateTimePicker.Text
print #f, "Offer Type :" & OfferTypeComboBox.Text
print #f, "Country Market : " & CountryMarketComboBox.Text
print #f, "tout le monde !"
print #f, "Company / Partner :" & CompanyPartnerComboBox.Text
print #f, "Communication Channel :" & ComChannelComboBox.Text
print #f, "Objectives :" & ObjectveRichTextBox.Text
print #f, "Cost Estimation :" & CostTextBox.Text
print #f, "Request made by :" & RequestTextBox.Text
print #f, "Comments :" & CommentRichTextBox.Text


' Fermeture du fichier
Close #f


End Sub





Private Sub EnvoiMail()
' ______________________________________________________________________
' envoi d'email
Dim OutlookApp As New Microsoft.Office.Interop.Outlook.Application
Dim NewMail As Microsoft.Office.Interop.Outlook.MailItem




NewMail = OutlookApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem)
NewMail.Recipients.Add("mail.mail@mail.com")
NewMail.Subject = "Demande de code Promo"
NewMail.Body = "il faudrait copier les lignes plus haut !"
NewMail.Send()


End Sub

_____________________________________________________________________

Private Sub ButtonSendIt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonSendIt.Click

Call Nombre()
Call Formulaire()
Call EnvoiMail()


End Sub


End Class



Merci d'avance Cordialement

john

A voir également:

1 réponse

manautop Messages postés 138 Date d'inscription lundi 27 novembre 2006 Statut Membre Dernière intervention 24 janvier 2013 3
25 janv. 2012 à 15:20
voici la solution

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.Close()
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

TypeOfPromoCombo.ResetText()
OfferTypeComboBox.ResetText()
CountryMarketComboBox.ResetText()
CompanyPartnerComboBox.ResetText()
ComChannelComboBox.ResetText()
EnrollementTextBox.ResetText()
NumberNightTextBox.ResetText()
RevenueTextBox.ResetText()
RecruitmentextBox.ResetText()
CostTextBox.ResetText()
CostpointTextBox.ResetText()
CommentRichTextBox.ResetText()
RequestTextBox.ResetText()

End Sub

Private Sub EnvoiMail()
' ___________________________________________________________________________________________
' envoi d'email
Dim OutlookApp As New Microsoft.Office.Interop.Outlook.Application
Dim NewMail As Microsoft.Office.Interop.Outlook.MailItem

Dim NIFO As String
If RadioButton1.Checked Then
NIFO = "Network Involved"
Else
NIFO = "Flagship Opening"
End If


Dim a = "Type Of Promotion : " & TypeOfPromoCombo.Text & Chr(13)
Dim b = "Start Date Promotion : " & StartDateTimePicker.Text & Chr(13)
Dim c = "End Date Promotion : " & EndDateTimePicker.Text & Chr(13)
Dim d = "End Date Bonus 1st Stay : " & EndBonusDateTimePicker.Text & Chr(13)
Dim e = "Offer Type : " & OfferTypeComboBox.Text & Chr(13)
Dim f = "Country / Market : " & CountryMarketComboBox.Text & Chr(13)
Dim g = " " & NIFO & Chr(13)
Dim h = "Company / Partner : " & CompanyPartnerComboBox.Text & Chr(13)
Dim i = "Communication Channel : " & ComChannelComboBox.Text & Chr(13)
Dim j = "Number of Enrollment : " & Val(EnrollementTextBox.Text) & Chr(13)
Dim k = "Number of Nights : " & Val(NumberNightTextBox.Text) & Chr(13)
Dim l = "Revenue Generated : " & Val(RevenueTextBox.Text) & Chr(13)
Dim m = "Recruitement : " & Val(RecruitmentextBox.Text) & Chr(13)
Dim n = "Cost Estimation (EUR) : " & Val(CostTextBox.Text) & Chr(13)
Dim o = "Cost Estimation (POINTS) : " & Val(CostpointTextBox.Text) & Chr(13)
Dim p = "Comments : " & Val(CommentRichTextBox.Text) & Chr(13)
Dim q = "Request made by : " & RequestTextBox.Text & Chr(13)


'changement automatique
If CompanyPartnerComboBox.Text = "Air Berlin -Top Bonus" Then 'Si numérique
CostpointTextBox.Text = (CostTextBox.Text * 0.013)
Else 'Sinon on vide le contenu
CostTextBox.Text = ""
CostpointTextBox.Text = ""
End If


NewMail = OutlookApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem)
NewMail.Recipients.Add("jonathan.sebban@accor.com")
NewMail.Subject = "Demande de code Promo"
NewMail.Body = q & a & b & c & d & e & f & g & h & i & j & k & l & m & n & o & p
NewMail.Send()


End Sub


Private Sub ButtonSendIt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonSendIt.Click

Call EnvoiMail()

End Sub

End Class
1