public bool SendSMS(SMSDto dto) { try { _commonTokens = _commonTokens ?? new List <Token>(); #region token replacement //replcaing sms text with default tokens dto.SMSText = _tokenHelperService.Replace(dto.SMSText, _commonTokens, true); //replacing sms text with sms specific tokens dto.SMSText = _tokenHelperService.Replace(dto.SMSText, dto.SMSSpecificTokens, true); #endregion string accountSid = _accountSID; string authToken = _authenticationToken; TwilioClient.Init(accountSid, authToken); var to = new PhoneNumber(dto.SMSToPhoneNumber); var message = MessageResource.Create( to, from: new PhoneNumber(_smsFromPhoneNumber), // From number, must be an SMS-enabled Twilio number ( This will send sms from ur "To" numbers ). body: dto.SMSText); return(true); } catch (Exception ex) { _loggerService.Error(ex, ex.Message, null); return(true); } }
public async Task <bool> SendEmail(EmailDto emailDto) { try { var client = new SendGridClient(_apikey); var from = new EmailAddress(_fromEmailId, _senderName); var to = new EmailAddress(emailDto.ToEmailAddress, emailDto.ToName); var substitutions = new List <Dictionary <string, string> > { }; _commonTokens = _commonTokens ?? new List <Token>(); #region token replacement for subject and body //replacing common tokens in subject emailDto.Subject = _tokenHelperService.Replace(emailDto.Subject, _commonTokens, true); //replacing email specific tokens in subject emailDto.Subject = _tokenHelperService.Replace(emailDto.Subject, emailDto.EmailSpecificTokens, true); //replacing common tokens in body emailDto.Body = _tokenHelperService.Replace(emailDto.Body, _commonTokens, true); //replacing email specific tokens in body emailDto.Body = _tokenHelperService.Replace(emailDto.Body, emailDto.EmailSpecificTokens, true); #endregion var msg = MailHelper.CreateSingleEmailToMultipleRecipients(from, new List <EmailAddress> { to }, emailDto.Subject, string.Empty, emailDto.Body); var response = await client.SendEmailAsync(msg); return(response.StatusCode == System.Net.HttpStatusCode.Accepted); } catch (AggregateException ae) { foreach (var e in ae.InnerExceptions) { // Handle the custom exception. await _loggerService .Error(e, "Aggregate exception thrown - " + e.Message, e.StackTrace); } } catch (Exception ex) { await _loggerService.Error(ex, ex.Message, null); } return(false); }