Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.15 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Data;
  8. using System.Windows.Documents;
  9. using System.Windows.Input;
  10. using System.Windows.Media;
  11. using System.Windows.Media.Imaging;
  12. using System.Windows.Navigation;
  13. using System.Windows.Shapes;
  14. using System.Net.Mail;
  15. using System.ComponentModel;
  16. using Microsoft.Win32;
  17. using System.Collections;
  18.  
  19. namespace Email
  20. {
  21.     /// <summary>
  22.     /// Interaction logic for MainWindow.xaml
  23.     /// </summary>
  24.     public partial class MainWindow : Window
  25.     {
  26.         ArrayList vastaanottajat = new ArrayList();
  27.         ArrayList vastaanottajatKopio = new ArrayList();
  28.         public MainWindow()
  29.         {
  30.             InitializeComponent();
  31.         }
  32.  
  33.         private void Lahetetty(object sender, AsyncCompletedEventArgs e)
  34.         {
  35.             // Get the unique identifier for this asynchronous operation.
  36.             String token = (string)e.UserState;
  37.  
  38.             if (e.Cancelled)
  39.             {
  40.                 MessageBox.Show("Lähettäminen peruttu");
  41.                 return;
  42.             }
  43.             if (e.Error != null)
  44.             {
  45.                 MessageBox.Show("Lähetysvirhe: " + token + " " + e.Error.ToString());
  46.                 return;
  47.             }
  48.             MessageBox.Show("Viesti lähetetty");
  49.            
  50.             RegistryKey r = Registry.CurrentUser;
  51.             RegistryKey email = r.CreateSubKey("Email");
  52.             RegistryKey nimi = email.CreateSubKey("Nimi");
  53.             RegistryKey osoite = email.CreateSubKey("Postiosoite");
  54.             RegistryKey signature = email.CreateSubKey("Signature");
  55.             nimi.SetValue("nimi", textBoxLahettajanNimi.Text);
  56.             osoite.SetValue("osoite", textBoxLahettajanOsoite.Text);
  57.         }
  58.              
  59.         private void button1_Click(object sender, RoutedEventArgs e)
  60.         {
  61.            
  62.             foreach (MailAddress vastaanottaja in vastaanottajat)
  63.             {
  64.                 vastaanottajatKopio.Add(vastaanottaja);
  65.                 MailMessage message = new MailMessage(textBoxLahettajanOsoite.Text, textBoxVastaanottajanOsoite.Text);
  66.                 message.Subject = textBoxViestinAihe.Text;
  67.                
  68.  
  69.                 RegistryKey r = Registry.CurrentUser;
  70.                 RegistryKey email = r.CreateSubKey("Email");
  71.                 RegistryKey signature = email.CreateSubKey("Signature");
  72.                 signature.SetValue("signature", textBoxSignature.Text);
  73.                 string allekirjoitus = (String)signature.GetValue("signature");
  74.                 if (allekirjoitus.Length > 0)
  75.                 {
  76.                     string viestiSignaturella = textBoxViesti.Text + "\n" + "\n" +  "-- " + allekirjoitus;
  77.                     message.Body = viestiSignaturella;
  78.                 }
  79.                 else
  80.                 {
  81.                     message.Body = textBoxViesti.Text;
  82.                 }
  83.                 SmtpClient client = new SmtpClient("mail.kolumbus.fi");
  84.                 client.SendCompleted += new SendCompletedEventHandler(Lahetetty);
  85.                 string userState = "test message1"; // voi olla mitä tahansa
  86.                 client.SendAsync(message, userState);
  87.             }
  88.             vastaanottajat.Clear();
  89.         }
  90.  
  91.         private void Window_Loaded(object sender, RoutedEventArgs e)
  92.         {
  93.            
  94.             RegistryKey r = Registry.CurrentUser;
  95.             RegistryKey email = r.CreateSubKey("Email");
  96.             RegistryKey nimi = email.CreateSubKey("Nimi");
  97.             RegistryKey osoite = email.CreateSubKey("Postiosoite");
  98.             RegistryKey signature = email.CreateSubKey("Signature");
  99.             textBoxLahettajanNimi.Text = (String)nimi.GetValue("nimi");
  100.             textBoxLahettajanOsoite.Text = (String)osoite.GetValue("osoite");
  101.             textBoxSignature.Text = (String)signature.GetValue("signature");
  102.         }
  103.  
  104.         private void button2_Click_1(object sender, RoutedEventArgs e)
  105.         {
  106.             vastaanottajat.Add(new MailAddress(textBoxVastaanottajanOsoite.Text));
  107.         }
  108.        
  109.         }
  110.  
  111.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement