Bonjour à tous ! Je suis débutant en C et j'ai un petit problème avec GTK...
Je ne comprends pas comment réexploiter des données saisies par l'utilisateur dans des formulaires.
Mon but est d'envoyer un mail à un utilisateur (smtp et tout le blabla). Pour le moment j'arrive à m'envoyer des mails. Mais je dois préciser dans le code source le destinataire, le message etc... Donc ce n'est pas dynamique.
Je suis arrivé à faire de facon dynamique l'envoit du message. Mais je dois toujours préciser dans mon code le destinataire et celui qui envoit le message.
Car je n'arrive pas à réexploitez c'que l'utilisateur a écrit dans le champs "TO:" je n'arrive que dans le message.
(Je ne sais pas si je suis très claire T_T)
Voila un morceau de monde code source !
(je suis nul en anglais donc je pense que j'ai du mal traduire mes coms... Mais comme je dois le faire en anglais... Ben...)
La fonction qui crée un fichier texte, execute l'envoit du mail (un autre.exe) qui prend en compte le fichier txt crée et après l'envoi du mail elle efface le fichier texte. (elle exploite le champ texte de mon mail mais je ne sais pas comment exploitez le champ to)
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59 void NewMail() { GtkWidget *NewMailWindow = NULL; /* New Mail Window */ GtkWidget *pVBox = NULL; /* Vertical Box */ GtkWidget *pHBox = NULL; GtkWidget* pTextView = NULL; GtkWidget* pButton = NULL; GtkWidget *pEntry = NULL; GtkWidget *pLabel = NULL; NewMailWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL); // to create a complete window not a pop up window ! gtk_window_set_title ( GTK_WINDOW(NewMailWindow), "New Mail"); // Title of the main Window gtk_window_set_default_size(GTK_WINDOW(NewMailWindow),800,600); // Size of the mail Window gtk_window_set_position(GTK_WINDOW(NewMailWindow),GTK_WIN_POS_CENTER); // Default position of the mail window pVBox = gtk_vbox_new(FALSE, 5); gtk_container_add(GTK_CONTAINER(NewMailWindow), pVBox); /*** To , Cc: , Cci and Object ***/ /* Creation et insertion des elements contenus dans le premier GtkFrame */ pLabel = gtk_label_new("To :"); gtk_box_pack_start(GTK_BOX(pVBox), pLabel, FALSE, FALSE, 0); pEntry = gtk_entry_new(); gtk_box_pack_start(GTK_BOX(pVBox), pEntry, FALSE, FALSE, 0); pLabel = gtk_label_new("Cc :"); gtk_box_pack_start(GTK_BOX(pVBox), pLabel, FALSE, FALSE, 0); pEntry = gtk_entry_new(); gtk_box_pack_start(GTK_BOX(pVBox), pEntry, FALSE, FALSE, 0); pLabel = gtk_label_new("Cci :"); gtk_box_pack_start(GTK_BOX(pVBox), pLabel, FALSE, FALSE, 0); pEntry = gtk_entry_new(); gtk_box_pack_start(GTK_BOX(pVBox), pEntry, FALSE, FALSE, 0); pLabel = gtk_label_new("Object :"); gtk_box_pack_start(GTK_BOX(pVBox), pLabel, FALSE, FALSE, 0); pEntry = gtk_entry_new(); gtk_box_pack_start(GTK_BOX(pVBox), pEntry, FALSE, FALSE, 0); /*** Where the user write his mail***/ pEntry = gtk_text_view_new(); gtk_box_pack_start(GTK_BOX(pVBox), pEntry, TRUE, TRUE, 0); /*** To send his mail ***/ pButton=gtk_button_new_with_label("Envoyer"); gtk_box_pack_start(GTK_BOX(pVBox),pButton,FALSE,FALSE,0); g_signal_connect(G_OBJECT(pButton), "clicked", G_CALLBACK(SendMail), (gpointer) pEntry); gtk_widget_show_all(NewMailWindow); /* display all the mail box */ return EXIT_SUCCESS; }
ps: je comprends pas tout c'que je fais mais comme cela marche T_T... Enfin presque...
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
32
33
34
35
36
37
38 /*** Send a mail ***/ void SendMail(GtkWidget *pWidget, gpointer *data) { GtkWidget *pEntry; GtkTextBuffer* pTextBuffer; GtkTextIter iStart; GtkTextIter iEnd; gchar* sBuffer; pEntry = GTK_WIDGET(data); /* On recupere le buffer */ pTextBuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(pEntry)); /* On recupere l'origine du buffer */ gtk_text_buffer_get_start_iter(pTextBuffer, &iStart); /* On recupere la fin du buffer */ gtk_text_buffer_get_end_iter(pTextBuffer, &iEnd); /* On copie le contenu du buffer dans une variable */ sBuffer = gtk_text_buffer_get_text(pTextBuffer, &iStart, &iEnd, TRUE); FILE* file = NULL; file = fopen("mail.txt", "w+"); fprintf(file, "mail.blabla.com\n\n" "blabla@blabla.com\n" "blabla@blabla.com\n" "From: \"Ajite\" <blabla@blabla.com>\n" "To: \"blabla\" <blabla@blabla.com>\n" "Subject: Test smtp\n\n" "%s %s ", sBuffer,sBuffer); fclose(file); system("mail.exe mail.txt"); remove("mail.txt"); return 0; }
Merci d'avance.
Partager