コード例 #1
0
        private async void btnSendEmail_Click(object sender, RoutedEventArgs e)
        {
            using (var MDContext = new MessageDataContext())
            {
                var wpfEmailer = WPFEmailer.getEmailerInstance(
                    txtUserName.Text,
                    txtTo.Text,
                    txtUserName.Text,
                    txtPassword.Password,
                    txtSubject.Text,
                    txtBody.Text);
                MessageData messageData = new MessageData(ID++, txtUserName.Text, txtBody.Text);
                MDContext.messageDatas.Add(messageData);
                await MDContext.SaveChangesAsync();

                //TODO вынести это в настройки
                //wpfEmailer.Host = txtSMTPServerName.Text;
                //wpfEmailer.Port = Convert.ToInt32(txtSMTPPortNumber.Text);
                try
                {
                    wpfEmailer.SendEmail();
                    MessageBox.Show("Message send successfully.");
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error:" + ex.ToString());
                }
            }
        }
コード例 #2
0
 public static WPFEmailer getEmailerInstance(string from, string to, string user, string password, string subject, string body)
 {
     if (EmailerInstance == null)
     {
         EmailerInstance = new WPFEmailer(from, to, user, password, subject, body);
     }
     return(EmailerInstance);
 }