private void sendButton_Click(object sender, RoutedEventArgs e) { try { using (SmtpConnection smtpConnection = new SmtpConnection()) { smtpConnection.Connect("smtp.gmail.com", 587); smtpConnection.ExtendedHello("Hello"); smtpConnection.StartTls("smtp.gmail.com"); smtpConnection.ExtendedHello("Hello"); smtpConnection.AuthPlain(User.Account.Gmail, User.Account.Password); smtpConnection.Mail(User.Account.Gmail); smtpConnection.Recipient(toTextBox.Text); smtpConnection.Data(EmailFormatter.GetText(User.Account.Gmail, subjectTextBox.Text, toTextBox.Text, null, messageText.Text)); MessageBox.Show("OK"); } } catch (Exception exception) { MessageBox.Show(exception.Message); } finally { WindowController.Instance.sendMessageWindow.Hide(); WindowController.Instance.allMessagesWindow.Show(); } }
public void TestNormalizeAcsiiAddress() { var emailFormatter = new EmailFormatter(); string[] addresses = { "*****@*****.**", "*****@*****.**", "*****@*****.**", "*****@*****.**", "*****@*****.**", "*****@*****.**", // (may go to [email protected] inbox depending on mail server) "*****@*****.**", // (one-letter local-part) "*****@*****.**", "admin@mailserver1", // (local domain name with no TLD, although ICANN highly discourages dotless email addresses[13]) "*****@*****.**", // (see the List of Internet top-level domains) "\" \"@example.org", // (space between the quotes) "\"john..doe\"@example.org", // (quoted double dot) "[email protected]", // (bangified host route used for uucp mailers) "*****@*****.**", // (% escaped mail route to [email protected] via example.org) }; foreach (var address in addresses) { var result = emailFormatter.NormalizeEmail(address); Assert.AreEqual(address, result, String.Format("Expected for '{0}': true; Actual: {1}", address, result)); } }
static void TestEmailFormatter() { var en = new EmailFormatter(); Console.WriteLine(en.UnicodeToPunycode("с-балалайкой.рф")); Console.WriteLine(en.NormalizeEmail("медведь@с-балалайкой.рф")); }
public void ConvertRecipientCollectionToString_Has_Proper_Divider() { string recipientsAsString = EmailFormatter.ConvertRecipientCollectionToString(_recipients); char testDivider = ';'; Assert.IsTrue(recipientsAsString.Contains(EmailerConstants.EMAIL_FORMAT_DIVIDER_CHARACTER.ToString())); Assert.IsTrue(EmailFormatter.ConvertRecipientCollectionToString(_recipients, testDivider).Contains(testDivider.ToString())); }
/// <summary> /// Sends an email with the provided subject and body to the provided recipient(s). /// </summary> /// <param name="smtp">The mail server to use for sending the email.</param> /// <param name="emailFrom">A collection of senders of the email (who it's from).</param> /// <param name="emailTo">A collection of recipients of the email (who it is going to).</param> /// <param name="subject">The subject line of the email.</param> /// <param name="body">The body of the email.</param> /// <param name="emailCc">A collection of Carbon-Copy recipients of the email (who is included to be sent to).</param> /// <param name="emailBcc">A collection of blind Carbon-Copy recipients of the email (who is included to be sent to).</param> /// <param name="priority">The priority of the email.</param> /// <param name="attachments">Any attachments to be attached to the email.</param> /// <exception cref="ArgumentNullException">If the provided smtp, emailTo, or emailFrom fields are NULL.</exception> public static void SendEmail(string smtp, IEnumerable <string> emailFrom, IEnumerable <string> emailTo, string subject, string body, IEnumerable <string> emailCc, IEnumerable <string> emailBcc, MailPriority?priority, IEnumerable <Attachment> attachments) { string emailToString = EmailFormatter.ConvertRecipientCollectionToString(emailTo); string emailFromString = EmailFormatter.ConvertRecipientCollectionToString(emailFrom); string emailCcString = EmailFormatter.ConvertRecipientCollectionToString(emailCc, EmailerConstants.EMAIL_CC_DIVIDER_CHARACTER); string emailBccString = EmailFormatter.ConvertRecipientCollectionToString(emailBcc, EmailerConstants.EMAIL_CC_DIVIDER_CHARACTER); SendEmail(smtp, emailFromString, emailToString, subject, body, emailCcString, emailBccString, priority, attachments); }
public void TestNormalizeEAIAddressInPunicode() { var emailFormatter = new EmailFormatter(); string[,] addresses = { { "медведь@xn----8sbaac5cahfb0b0a.xn--p1ai", "медведь@с-балалайкой.рф" }, // Cyrillic characters { "[email protected]", "user@с-балалайкой.рф" }, // Cyrillic characters, ASCII local part { "δοκιμή@xn--hxajbheg2az3al.xn--jxalpdlp", "δοκιμή@παράδειγμα.δοκιμή" }, // Greek alphabet }; for (int i = 0; i < addresses.GetLength(0); i++) { var result = emailFormatter.NormalizeEmail(addresses[i, 0]); Assert.AreEqual(addresses[i, 1], result, String.Format("Expected for '{0}': true; Actual: {1}", addresses[i, 1], result)); } }
public EmailTemplateFixture() { Task.Run(async() => { Directory.CreateDirectory("_out"); var serviceCollection = new ServiceCollection(); serviceCollection.AddMjmlServices(); var mjmlServices = serviceCollection.BuildServiceProvider() .GetRequiredService <IMjmlServices>(); EmailFormatter = new EmailFormatter(ImageFormatter, mjmlServices); App.EmailTemplates["en"] = await EmailFormatter.GetDefaultTemplateAsync(); }).Wait(); }
public void TestNormalizeEAIAddressInUnicode() { var emailFormatter = new EmailFormatter(); string[] addresses = { "Pelé@example.com", // Latin alphabet with diacritics "δοκιμή@παράδειγμα.δοκιμή", // Greek alphabet "我買@屋企.香港", // Traditional Chinese characters "二ノ宮@黒川.日本", // Japanese characters "медведь@с-балалайкой.рф", // Cyrillic characters "संपर्क@डाटामेल.भारत", // Devanagari characters }; foreach (var address in addresses) { var result = emailFormatter.NormalizeEmail(address); Assert.AreEqual(address, result, String.Format("Expected for '{0}': true; Actual: {1}", address, result)); } }
private void sendButton_Click(object sender, RoutedEventArgs e) { try { var userInfo = Login.Split('@'); var login = userInfo[0]; SmtpHost = userInfo[1]; _smtp.Connect("smtp." + SmtpHost, 587); _smtp.ExtendedHello("Hello"); // переходим в защищенное соединение // параметр отвечает за адрес домена, по которому будет проверяется SSL-сертификат _smtp.StartTls("smtp." + SmtpHost); // снова отправляем extended hello, таковы требования протокола _smtp.ExtendedHello("Hello"); // авторизуемся _smtp.AuthPlain(login, Password); string email = ToEmailTextBox.Text; Regex regex = new Regex(@"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$"); Match match = regex.Match(email); if (!match.Success) { MessageBox.Show(email + " is incorrect"); return; } _smtp.Mail(Login + "@" + SmtpHost); _smtp.Recipient(ToEmailTextBox.Text); _smtp.Data(EmailFormatter.GetText(Login + "@" + SmtpHost, TopicTextBox.Text, ToEmailTextBox.Text, null, ContentOfMessageSubHeaderText.Text)); } catch (Exception ex) { MessageBox.Show("Введите правильно почту получателя"); return; } Close(); }
/// <summary> /// Method that wraps up our dialog waterfall. An email is sent to the user-given email /// and them proceeds to end the step context. /// </summary> /// <param name="stepContext">stepContext that keeps track of where we are in the waterfall</param> /// <returns>Task that is queued to be executed.</returns> private async Task <DialogTurnResult> GreetUserAsync(WaterfallStepContext stepContext) { var context = stepContext.Context; var basicState = await UserProfileAccessor.GetAsync(context); // Send our email via SendGrid await _emailSender.SendEmailAsync(basicState.Email, "Hello from a simple bot!", EmailFormatter.SimpleBotEmail()); // Nice informative message informing the user they should expect an email await context.SendActivityAsync( $"Thanks! I've sent a nifty email at {basicState.Email}! If you don't get it within a few minutes I hit my limit for the day!"); return(await stepContext.EndDialogAsync()); }
public void ConvertRecipientCollectionToString_Not_Null_And_Not_Empty() { Assert.That(EmailFormatter.ConvertRecipientCollectionToString(_recipients), Is.Not.Null.And.Not.Empty); }