示例#1
25
 // send
 private void button1_Click(object sender, RoutedEventArgs e)
 {
     if (!this.toComboBox.Text.IsEmail())
     {
         MessageBox.Show("Please enter a valid email!");
         return;
     }
     else
     {
         if (!Classes.Settings.Emails.Contains(toComboBox.SelectedItem.ToString()))
             Classes.Settings.Emails.Add(toComboBox.SelectedItem.ToString());
     }
     if (string.IsNullOrEmpty(this.subjectTextBox.Text))
     {
         if (MessageBox.Show("Subject is empty! Continue?", "XMail", MessageBoxButton.YesNo) == MessageBoxResult.No)
             return;
     }
     try
     {
         ActiveUp.Net.Mail.SmtpMessage msg = new ActiveUp.Net.Mail.SmtpMessage();
         AccountSettings.AccountInfo ac = XMail.Classes.Settings.Account.Accounts[0];
         ActiveUp.Net.Mail.MimeBody body = new ActiveUp.Net.Mail.MimeBody(ActiveUp.Net.Mail.BodyFormat.Html);
         body.Text = htmlEditor.DocumentHtml;
         msg.BodyHtml = body;
         msg.To.Add(new ActiveUp.Net.Mail.Address(this.toComboBox.Text));
         msg.Subject = subjectTextBox.Text;
         msg.Sender = new ActiveUp.Net.Mail.Address(ac.EmailAddress, ac.UserName);
         foreach (string fn in Attchements)
         {
             msg.Attachments.Add(fn, false);
         }
         if (ac.OutgoingIsSSL)
         {
             if (ac.OutPortEnabled)
                 msg.SendSsl(ac.OutgoingServerName, ac.OutPort, ac.EmailAddress, ac.Password, ActiveUp.Net.Mail.SaslMechanism.Login);
             else
                 msg.SendSsl(ac.OutgoingServerName, ac.EmailAddress, ac.Password, ActiveUp.Net.Mail.SaslMechanism.Login);
         }
         else
         {
             if (ac.OutPortEnabled)
                 msg.Send(ac.OutgoingServerName, ac.OutPort, ac.EmailAddress, ac.Password, ActiveUp.Net.Mail.SaslMechanism.Login);
             else
                 msg.Send(ac.OutgoingServerName, ac.EmailAddress, ac.Password, ActiveUp.Net.Mail.SaslMechanism.Login);
         }
         Classes.StaticManager.SentMessages.Add(msg);
         if (!Directory.Exists(System.Windows.Forms.Application.LocalUserAppDataPath + "\\..\\SentMessages\\"))
             Directory.CreateDirectory(System.Windows.Forms.Application.LocalUserAppDataPath + "\\..\\SentMessages\\");
         Serializer.Serialize(msg, System.Windows.Forms.Application.LocalUserAppDataPath + "\\..\\SentMessages\\msg" + new IExtendFramework.Random.RandomNumberGenerator(DateTime.Now.Millisecond).Next().ToString() + new IExtendFramework.Random.RandomNumberGenerator(DateTime.Now.Millisecond).Next().ToString() + ".sent");
         Tasks.TaskManager.AddTask(new Tasks.UpdateEmailTask());
         Close();
     }
     catch (Exception ex)
     {
         IExtendFramework.Controls.AdvancedMessageBox.TaskDialog.Show(new IExtendFramework.Controls.AdvancedMessageBox.TaskDialogOptions()
         {
             Content = "Error: " + ex.Message,
             Title = "Error",
             ExpandedInfo = "Full details: " + ex.ToString()
         });
     }
 }
示例#2
0
        private void button2_Click(object sender, EventArgs e)
        {
            // We create the message object

            ActiveUp.Net.Mail.SmtpMessage message = new ActiveUp.Net.Mail.SmtpMessage();

            // We assign the sender email
            message.From.Email = "*****@*****.**";

            // We assign the recipient email
            message.To.Add("*****@*****.**");

            // We assign the subject
            message.Subject = "PUTO";

            // We add the embedded objets.
            message.BodyHtml.Text = "The message doens't contain embedded objects.";


            message.BuildMimePartTree();
            message.Send("smtps://smtp.gmail.com", 587, "cloudifydtest", "cloudifyd123", SaslMechanism.Login);
        }
示例#3
-50
 /// <summary>
 /// This static method allows to send an email in 1 line of code.
 /// </summary>
 /// <param name="from">The email address of the person sending the message.</param>
 /// <param name="to">The email address of the message's recipient.</param>
 /// <param name="subject">The message's subject.</param>
 /// <param name="textBody">The text body of the message.</param>
 /// <example>
 /// C#
 /// 
 /// SmtpClient.QuickSend("*****@*****.**","*****@*****.**","Test","Hello this is a test!",BodyFormat.Text,"C:\\My Documents\\file.doc","mail.myhost.com");
 ///
 /// VB.NET
 /// 
 /// SmtpClient.QuickSend("*****@*****.**","*****@*****.**","Test","Hello this is a test!",BodyFormat.Text,"C:\My Documents\file.doc","mail.myhost.com")
 /// 
 /// JScript.NET
 /// 
 /// SmtpClient.QuickSend("*****@*****.**","*****@*****.**","Test","Hello this is a test!",BodyFormat.Text,"C:\\My Documents\\file.doc","mail.myhost.com");
 /// </example>
 public static void QuickSend(string from, string to, string subject, string body, BodyFormat bodyFormat, string attachmentPath, string smtpServer)
 {
     ActiveUp.Net.Mail.SmtpMessage message = new ActiveUp.Net.Mail.SmtpMessage();
     message.From = new ActiveUp.Net.Mail.Address(from);
     message.To.Add(to);
     message.Subject = subject;
     if (bodyFormat == BodyFormat.Text)
         message.BodyText.Text = body;
     else
         message.BodyHtml.Text = body;
     if (!string.IsNullOrEmpty(attachmentPath))
         message.Attachments.Add(attachmentPath, false);
     if (!string.IsNullOrEmpty(smtpServer))
         message.Send(smtpServer);
     else
         message.DirectSend();
 }