Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- using System.Net.Mail;
- using System.ComponentModel;
- using Microsoft.Win32;
- using System.Collections;
- namespace Email
- {
- /// <summary>
- /// Interaction logic for MainWindow.xaml
- /// </summary>
- public partial class MainWindow : Window
- {
- ArrayList vastaanottajat = new ArrayList();
- ArrayList vastaanottajatKopio = new ArrayList();
- public MainWindow()
- {
- InitializeComponent();
- }
- private void Lahetetty(object sender, AsyncCompletedEventArgs e)
- {
- // Get the unique identifier for this asynchronous operation.
- String token = (string)e.UserState;
- if (e.Cancelled)
- {
- MessageBox.Show("Lähettäminen peruttu");
- return;
- }
- if (e.Error != null)
- {
- MessageBox.Show("Lähetysvirhe: " + token + " " + e.Error.ToString());
- return;
- }
- MessageBox.Show("Viesti lähetetty");
- RegistryKey r = Registry.CurrentUser;
- RegistryKey email = r.CreateSubKey("Email");
- RegistryKey nimi = email.CreateSubKey("Nimi");
- RegistryKey osoite = email.CreateSubKey("Postiosoite");
- RegistryKey signature = email.CreateSubKey("Signature");
- nimi.SetValue("nimi", textBoxLahettajanNimi.Text);
- osoite.SetValue("osoite", textBoxLahettajanOsoite.Text);
- }
- private void button1_Click(object sender, RoutedEventArgs e)
- {
- foreach (MailAddress vastaanottaja in vastaanottajat)
- {
- vastaanottajatKopio.Add(vastaanottaja);
- MailMessage message = new MailMessage(textBoxLahettajanOsoite.Text, textBoxVastaanottajanOsoite.Text);
- message.Subject = textBoxViestinAihe.Text;
- RegistryKey r = Registry.CurrentUser;
- RegistryKey email = r.CreateSubKey("Email");
- RegistryKey signature = email.CreateSubKey("Signature");
- signature.SetValue("signature", textBoxSignature.Text);
- string allekirjoitus = (String)signature.GetValue("signature");
- if (allekirjoitus.Length > 0)
- {
- string viestiSignaturella = textBoxViesti.Text + "\n" + "\n" + "-- " + allekirjoitus;
- message.Body = viestiSignaturella;
- }
- else
- {
- message.Body = textBoxViesti.Text;
- }
- SmtpClient client = new SmtpClient("mail.kolumbus.fi");
- client.SendCompleted += new SendCompletedEventHandler(Lahetetty);
- string userState = "test message1"; // voi olla mitä tahansa
- client.SendAsync(message, userState);
- }
- vastaanottajat.Clear();
- }
- private void Window_Loaded(object sender, RoutedEventArgs e)
- {
- RegistryKey r = Registry.CurrentUser;
- RegistryKey email = r.CreateSubKey("Email");
- RegistryKey nimi = email.CreateSubKey("Nimi");
- RegistryKey osoite = email.CreateSubKey("Postiosoite");
- RegistryKey signature = email.CreateSubKey("Signature");
- textBoxLahettajanNimi.Text = (String)nimi.GetValue("nimi");
- textBoxLahettajanOsoite.Text = (String)osoite.GetValue("osoite");
- textBoxSignature.Text = (String)signature.GetValue("signature");
- }
- private void button2_Click_1(object sender, RoutedEventArgs e)
- {
- vastaanottajat.Add(new MailAddress(textBoxVastaanottajanOsoite.Text));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement