public void Send(string to) { try { if (string.IsNullOrEmpty(From)) { throw new Exception("'From' cannot be empty"); } if (string.IsNullOrEmpty(to)) { throw new ArgumentException(nameof(to)); } var code = _verificationCode.Generate(out var result); var text = _parser.Parse(code); TwilioClient.Init(_configuration.AccountSid, _configuration.AuthToken); var message = MessageResource.Create( from: new PhoneNumber(From), to: new PhoneNumber(to), body: text ); MessageSentHandler?.Invoke(result, message); } catch (Exception ex) { VerificationCodoeExceptionHandler?.Invoke(ex); } }
public async void SendAsync <T>(Func <string, T> options) where T : class { try { if (options == null) { throw new ArgumentException(nameof(options)); } TwilioClient.Init(_configuration.AccountSid, _configuration.AuthToken); var code = _verificationCode.Generate(out var result); var param = options.Invoke(code); if (!(param is CreateMessageOptions)) { return; } var msgOption = param as CreateMessageOptions; var message = await MessageResource.CreateAsync(msgOption); MessageSentHandler?.Invoke(result, message); } catch (Exception ex) { VerificationCodoeExceptionHandler?.Invoke(ex); } }
public async void SendAsync(string to) { try { if (string.IsNullOrEmpty(From)) { throw new Exception("'From' cannot be empty"); } if (string.IsNullOrEmpty(to)) { throw new ArgumentException(nameof(to)); } var code = _verificationCode.Generate(out var result); var text = _parser.Parse(code); var message = new MimeMessage(); message.From.Add(new MailboxAddress(From)); message.To.Add(new MailboxAddress(to)); message.Body = new TextPart { Text = text }; using (var emailClient = new SmtpClient()) { await emailClient.ConnectAsync(_configuration.SmtpServer, _configuration.SmtpPort, _configuration.UseSsl); if (AuthenticateHandlerDelegate != null) { AuthenticateHandlerDelegate.Invoke(emailClient); } else { if (_configuration.RemoveXOauth2) { emailClient.AuthenticationMechanisms.Remove("XOAUTH2"); } emailClient.Authenticate(_configuration.SmtpUsername, _configuration.SmtpPassword); } await emailClient.SendAsync(message); MessageSentHandler?.Invoke(result, message); emailClient.Disconnect(true); } } catch (Exception ex) { VerificationCodoeExceptionHandler?.Invoke(ex); } }
public async void SendAsync <T>(Func <string, T> options) where T : class { try { if (options == null) { throw new ArgumentException(nameof(options)); } var code = _verificationCode.Generate(out var result); var param = options.Invoke(code); if (!(param is MimeMessage)) { return; } var message = param as MimeMessage; using (var emailClient = new SmtpClient()) { await emailClient.ConnectAsync(_configuration.SmtpServer, _configuration.SmtpPort, _configuration.UseSsl); if (AuthenticateHandlerDelegate != null) { AuthenticateHandlerDelegate.Invoke(emailClient); } else { if (_configuration.RemoveXOauth2) { emailClient.AuthenticationMechanisms.Remove("XOAUTH2"); } emailClient.Authenticate(_configuration.SmtpUsername, _configuration.SmtpPassword); } await emailClient.SendAsync(message); MessageSentHandler?.Invoke(result, message); emailClient.Disconnect(true); } } catch (Exception ex) { VerificationCodoeExceptionHandler?.Invoke(ex); } }
public async void SendAsync(string to) { if (string.IsNullOrEmpty(From)) { throw new Exception("'From' cannot be empty"); } if (string.IsNullOrEmpty(to)) { throw new ArgumentException(nameof(to)); } var code = _verificationCode.Generate(out var result); var text = _parser.Parse(code); TwilioClient.Init(_configuration.AccountSid, _configuration.AuthToken); var message = await CallResource.CreateAsync( from : new PhoneNumber(From), to : new PhoneNumber(to), url : new Uri( $"{Url ?? "http://twimlets.com/message?" + WebUtility.UrlEncode("Message[0]=")}{text}" ) ); MessageSentHandler?.Invoke(result, message); }