public string Send() { string retorno = string.Empty; Message.BodyEncoding = UTF8Encoding.UTF8; Message.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure; Message.From = new System.Net.Mail.MailAddress(FromAddress); FileAttached.ToList().ForEach(x => Message.Attachments.Add(new System.Net.Mail.Attachment(x))); ToAddress.ToList().ForEach(x => Message.To.Add(new System.Net.Mail.MailAddress(x))); ToAddressCopy.ToList().ForEach(x => Message.CC.Add(new System.Net.Mail.MailAddress(x))); Message.Subject = Subject; Message.Body = Body; Smtp.UseDefaultCredentials = false; Smtp.Timeout = 180000; Smtp.DeliveryMethod = SmtpDeliveryMethod.Network; Smtp.Credentials = new System.Net.NetworkCredential(Acount, PassWord); try { Smtp.Send(Message); retorno = ""; } catch (Exception ex_) { retorno = ex_.InnerException != null ? (ex_.InnerException).Message : ex_.Message; } return(retorno); }
/// <summary> /// SendEmail method useful for get email and prepare email template to send to customer /// </summary> private void SendEmail() { tracingService.Trace("Entered EmailSender.SendEmail()"); try { templateName = EmailTemplateName.Get(executionContext); queryString = ToAddress.Get(executionContext); category = Category.Get(executionContext); tracingService.Trace("EmailSender.SendEmail(), Template Name:{0} InPutEmailString: {1}, Category: {2}", queryString, templateName, category); if (!string.IsNullOrEmpty(templateName) && !string.IsNullOrEmpty(queryString)) { EntityCollection emails = null; if (queryString.TrimStart().StartsWith("<")) { emails = GetEmailsByFetchXML(); } else { emails = GetEmailByString(); } if (null != emails && emails.Entities.Count > 0) { PrepareEmail(emails); } } } catch (Exception ex) { throw ex; } }
protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback, object state) { MailMessage mail = new MailMessage(); mail.To.Add(ToAddress.Get(context)); mail.From = new MailAddress(FromAddress.Get(context)); mail.Subject = Subject.Get(context); mail.Body = Body.Get(context); mail.IsBodyHtml = true; SmtpClient smtp = new SmtpClient(); Action action = () => { ManualResetEvent manualResetEvent = new ManualResetEvent(false); smtp.SendCompleted += (o, args) => { manualResetEvent.Set(); Debug.WriteLine("Send Mail Completed"); }; smtp.SendAsync(mail, null); manualResetEvent.WaitOne(TimeSpan.FromSeconds(30)); }; context.UserState = action; return(action.BeginInvoke(callback, state)); }
public void SetMailTo(string emails) { var temp = emails.Split(';'); ToAddress.AddRange(temp); ToAddress.Remove(string.Empty); }
/// <summary> /// Set To Address to the Mail /// </summary> /// <param name="mailMessage"></param> /// <param name="mailMsg"></param> private void SetToaddress(System.Web.Mail.MailMessage mailMessage, MailMessage mailMsg) { try { //checking toAddress string is null or empty if it not null then add to mail if (!String.IsNullOrEmpty(ToAddress)) { //split the toAddress string and add to an array string[] toArray = ToAddress.Split(";".ToCharArray()); ValidateRecipientEmail(toArray);//validating the email address //if mail is net.mail if (IsSmtpClientMail) { foreach (string to in toArray.Where(to => !to.Equals(""))) { mailMsg.To.Add(to); //add toAddress array to mailmessage.To } } else { //if mail is web.mail set toAddress string to MailMessage.To ToAddress = ToAddress.TrimEnd(';'); mailMessage.To = ToAddress; //multiple to address } } else { //Toaddress is null the set ToFlag=1 ToFlag = 1; } } catch (Exception ex) { throw ex; } }
public void AddAddress(string value) { if (ToAddress == null) { ToAddress = new List <string>(); } ToAddress.Add(value); }
public string CalculateHash() { string fromAddressDER = BitConverter.ToString(FromAddress.toDer()).Replace("-", ""); string toAddressDER = BitConverter.ToString(ToAddress.toDer()).Replace("-", ""); string transactionData = fromAddressDER + toAddressDER + Amount; byte[] tdBytes = Encoding.ASCII.GetBytes(transactionData); return(BitConverter.ToString(SHA256.Create().ComputeHash(tdBytes)).Replace("-", "")); }
/// <summary> /// Sending mail in GF Networks /// </summary> /// <param name="recipeient">Receiver(Optional wil set to default recipients)</param> /// <param name="subject">Subject for the mail</param> /// <param name="bodyText">Content for the mail body</param> public static bool SendMail(string subject, string body) { try { if (EnableMails != "true") { return(false); } MailMessage mMailMessage = new MailMessage(); mMailMessage.From = new MailAddress(FromAddress); foreach (var item in ToAddress.Split(';')) { mMailMessage.To.Add(item); } foreach (var item in CCAddress.Split(';')) { mMailMessage.CC.Add(item); } mMailMessage.Subject = subject; mMailMessage.Body = body; mMailMessage.Priority = MailPriority.High; SmtpClient mSmtpClient = new SmtpClient(); mSmtpClient.Host = SmtpServer; if (Port != string.Empty) { mSmtpClient.Port = Convert.ToInt32(Port);// 587 } mSmtpClient.EnableSsl = true; ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return(true); }; mSmtpClient.Send(mMailMessage); } catch (SmtpException ex) { string strError = ex.Message; return(false); } catch (Exception ex) { string strError = ex.Message; return(false); } return(true); }
public bool SendEmailToServer() { SmtpClient email = new SmtpClient { DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false, EnableSsl = enableSsl, Host = host, Port = port, Credentials = new NetworkCredential(userName, password) }; string[] adrs = ToAddress.Split(';'); MailMessage msg = new MailMessage(userName, adrs[0]); msg.Subject = Subject; msg.Body = Body; if (adrs.Length > 1) { for (int i = 1; i < adrs.Length; i++) { msg.To.Add(adrs[i]); } } if (!string.IsNullOrEmpty(CcAddress)) { string[] adrscc = CcAddress.Split(';'); foreach (string adr in adrscc) { msg.To.Add(adr); } } foreach (string filename in attachments) { msg.Attachments.Add(new Attachment(filename)); } try { email.Send(msg); return(true); } catch (Exception ex) { return(false); } }
public override int GetHashCode() { unchecked { int result = (ToAddress != null ? ToAddress.GetHashCode() : 0); result = (result * 397) ^ (FromAddress != null ? FromAddress.GetHashCode() : 0); result = (result * 397) ^ (Subject != null ? Subject.GetHashCode() : 0); result = (result * 397) ^ (Body != null ? Body.GetHashCode() : 0); result = (result * 397) ^ (AttachmentData != null ? AttachmentData.GetHashCode() : 0); return(result); } }
public override int GetHashCode() { unchecked { var hashCode = (FromAddress != null ? FromAddress.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (ToAddress != null ? ToAddress.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (TokenName != null ? TokenName.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Symbol != null ? Symbol.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (TokenType != null ? TokenType.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (TokenId != null ? TokenId.GetHashCode() : 0); return(hashCode); } }
public bool Send() { bool mailSent = false; try { MailMessage Mail = new MailMessage(); if (ToAddress != null) { ToAddress.ForEach(x => Mail.To.Add(x)); } if (CcAddress != null) { CcAddress.ForEach(x => Mail.CC.Add(x)); } if (BccAddress != null) { BccAddress.ForEach(x => Mail.Bcc.Add(x)); } Mail.From = new MailAddress(this.FromAddress); Mail.Subject = this.Subject; Mail.Body = this.Body; Mail.IsBodyHtml = this.IsBodyHtml; if (Attachments.Count > 0) { foreach (var attchment in Attachments) { Mail.Attachments.Add(attchment); } } SmtpClient SMTP = new SmtpClient(this.SmtpAddress); SMTP.UseDefaultCredentials = false; SMTP.Credentials = new System.Net.NetworkCredential(this.UserName, this.Password); SMTP.Port = this.Port; SMTP.Host = this.SmtpAddress; SMTP.EnableSsl = this.SslEnabled; SMTP.Send(Mail); SMTP.Dispose(); Mail.Dispose(); mailSent = true; } catch (Exception ex) { mailSent = false; } return(mailSent); }
public override int GetHashCode() { unchecked { var hashCode = CashoutId.GetHashCode(); hashCode = (hashCode * 397) ^ ClientId.GetHashCode(); hashCode = (hashCode * 397) ^ (ToAddress != null ? ToAddress.GetHashCode() : 0); hashCode = (hashCode * 397) ^ Amount.GetHashCode(); hashCode = (hashCode * 397) ^ IndexInBatch.GetHashCode(); hashCode = (hashCode * 397) ^ AddedToBatchAt.GetHashCode(); return(hashCode); } }
public Boolean SendMessageWithQP() { using (var MailMessage = new MailMessage()) { MailMessage.From = new MailAddress(FromAddress); MailMessage.Subject = Subject; MailMessage.Body = Body; MailMessage.Priority = MailPriority; MailMessage.IsBodyHtml = IsBodyHTML; string[] toAddressSplit = ToAddress.Split(';'); var toContacts = (from item in toAddressSplit where !String.IsNullOrWhiteSpace(item) select item).ToArray(); if (toContacts.Length > 0) { MailMessage.To.Add(String.Join(",", toContacts)); } // Add the To CC Email Address in Bulk string[] toCCAddressSplit = ToAddressCC.Split(';'); var ccContacts = (from item in toCCAddressSplit where !String.IsNullOrWhiteSpace(item) select item).ToArray(); if (ccContacts.Length > 0) { MailMessage.CC.Add(String.Join(",", ccContacts)); } // Add message attachments in bulk if (Attachments != null && Attachments != string.Empty) { string[] attachmentsTemp = Attachments.Split(';'); foreach (string attachTemp in attachmentsTemp) { Attachment attach = new Attachment(attachTemp); attach.TransferEncoding = System.Net.Mime.TransferEncoding.QuotedPrintable; MailMessage.Attachments.Add(new Attachment(attachTemp)); } } using (SmtpClient client = new SmtpClient(SMTPServerName)) { client.Send(MailMessage); // MailMessage.Attachments.Dispose(); } return(true); } }
/// <summary> /// save the message. /// </summary> /// <returns></returns> public Boolean SaveMessage(string DocumentPath) { using (var MailMessage = new MailMessage()) { MailMessage.From = new MailAddress(FromAddress); MailMessage.Subject = Subject; MailMessage.Body = Body; MailMessage.Priority = MailPriority; MailMessage.IsBodyHtml = IsBodyHTML; string[] toAddressSplit = ToAddress.Split(';'); var toContacts = (from item in toAddressSplit where !String.IsNullOrWhiteSpace(item) select item).ToArray(); if (toContacts.Length > 0) { MailMessage.To.Add(String.Join(",", toContacts)); } // Add the To CC Email Address in Bulk string[] toCCAddressSplit = ToAddressCC.Split(';'); var ccContacts = (from item in toCCAddressSplit where !String.IsNullOrWhiteSpace(item) select item).ToArray(); if (ccContacts.Length > 0) { MailMessage.CC.Add(String.Join(",", ccContacts)); } // Add message attachments in bulk if (Attachments != null && Attachments != string.Empty) { string[] attachmentsTemp = Attachments.Split(';'); foreach (string attachTemp in attachmentsTemp) { MailMessage.Attachments.Add(new Attachment(attachTemp)); } } using (SmtpClient client = new SmtpClient(SMTPServerName)) { client.PickupDirectoryLocation = DocumentPath; client.DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory; client.Send(MailMessage); } return(true); } }
private async Task SendExecute() { string tx = string.Empty; try { if (IsBusy) { return; } IsBusy = true; DialogService.ShowLoading(); if (!string.IsNullOrEmpty(ToAddress) && Quantity > 0 && SelectedItem != null) //todo address validation { var scriptHash = ToAddress.ToScriptHash(); // throws exception if address is not valid if (_assetsPicker.TryGetValue(SelectedItem, out var contractHash)) { tx = await _walletService.TransferNep5(ToAddress, Quantity, contractHash); } } } catch (Exception ex) { if (ex is RpcClientUnknownException || ex is RpcClientTimeoutException) //todo switch error message { AppSettings.ChangeRpcServer(); } await DialogService.ShowAlertAsync(ex.Message, AppResource.Alert_Error); } finally { IsBusy = false; DialogService.HideLoading(); if (!string.IsNullOrEmpty(tx)) { await DialogService.ShowAlertAsync("Asset sent. It might take a few minutes for update balance.", "Success"); //todo localization ToAddress = string.Empty; Quantity = 0; } else { await DialogService.ShowAlertAsync(AppResource.Alert_SomethingWrong, AppResource.Alert_Error); //todo localization } } }
internal void Populate(Settings settings) { var s = settings.Email; if (ToAddress.HasValue()) { s.ToAddress = ToAddress; } if (FromAddress.HasValue()) { s.FromAddress = FromAddress; } if (FromDisplayName.HasValue()) { s.FromDisplayName = FromDisplayName; } if (SMTPHost.HasValue()) { s.SMTPHost = SMTPHost; } if (SMTPPort.HasValue) { s.SMTPPort = SMTPPort; } if (SMTPUserName.HasValue()) { s.SMTPUserName = SMTPUserName; } if (SMTPPassword.HasValue()) { s.SMTPPassword = SMTPPassword; } if (SMTPEnableSSL.HasValue) { s.SMTPEnableSSL = SMTPEnableSSL.Value; } if (PreventDuplicates.HasValue) { s.PreventDuplicates = PreventDuplicates.Value; } if (s.ToAddress.HasValue()) { EmailNotifier.Setup(s); } }
/// <summary> /// Add the given email address to 'TO' address list /// </summary> /// <param name="toAddress">The email address to add</param> public void AddToAddress(string toAddress) { if (!string.IsNullOrEmpty(toAddress)) { if (string.IsNullOrEmpty(this.ToAddress)) { this.ToAddress = toAddress; } else if (ToAddress.EndsWith(",")) { this.ToAddress = this.ToAddress + toAddress; } else { this.ToAddress = this.ToAddress + "," + toAddress; } } }
public void DebugDump() { string html = ""; if (Subject.IsNotBlank()) { html += "Subject: " + Subject.HtmlEncode() + "<br>"; } if (FromAddress.IsNotBlank()) { html += "FromAddress: " + FromAddress.HtmlEncode() + "<br>"; } if (FromName.IsNotBlank()) { html += "FromName: " + FromName.HtmlEncode() + "<br>"; } if (ToAddress.IsNotBlank()) { html += "ToAddress: " + ToAddress.HtmlEncode() + "<br>"; } if (ToName.IsNotBlank()) { html += "ToName: " + ToName.HtmlEncode() + "<br>"; } if (CC.IsNotBlank()) { html += "CC: " + CC.HtmlEncode() + "<br>"; } if (BCC.IsNotBlank()) { html += "BCC: " + BCC.HtmlEncode() + "<br>"; } if (BodyHtml.IsNotBlank()) { html += "BodyHtml: " + BodyHtml + "<br>"; } if (BodyPlain.IsNotBlank()) { html += "BodyPlain: " + BodyPlain.HtmlEncode() + "<br>"; } Web.Write(html); }
public CallResult <List <ShippingMethodViewModel> > GetShippingOptionsModel(IUnitOfWork db, ITime time, ILogService log, IShipmentApi rateProvider, IWeightService weightService, IShippingService shippingService, IList <OrderItemRateInfo> orderItems) { var result = new CallResult <List <ShippingMethodViewModel> >(); var fromAddress = FromAddress.GetAddressDto(); var toAddress = ToAddress.GetAddressDto(); if (AddressHelper.IsEmpty(fromAddress) || AddressHelper.IsEmpty(toAddress)) { result.Status = CallStatus.Fail; result.Message = "Empty from/to address"; } result = GetShippingOptionsWithRate(db, log, time, rateProvider, shippingService, fromAddress, toAddress, time.GetAppNowTime(), WeightLb ?? 0, (decimal)(WeightOz ?? 0), 0, new OrderRateInfo() { Items = orderItems, }); return(result); }
public override int GetHashCode() { int hash = 1; if (OwnerAddress.Length != 0) { hash ^= OwnerAddress.GetHashCode(); } if (ToAddress.Length != 0) { hash ^= ToAddress.GetHashCode(); } if (Amount != 0L) { hash ^= Amount.GetHashCode(); } if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
public override int GetHashCode() { unchecked { var hashCode = (Chain != null ? Chain.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (TokenTransfers != null ? TokenTransfers.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Status != null ? Status.GetHashCode() : 0); hashCode = (hashCode * 397) ^ Index; hashCode = (hashCode * 397) ^ (TransactionHash != null ? TransactionHash.GetHashCode() : 0); hashCode = (hashCode * 397) ^ Value.GetHashCode(); hashCode = (hashCode * 397) ^ (FromAddress != null ? FromAddress.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (ToAddress != null ? ToAddress.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Date != null ? Date.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (BlockHash != null ? BlockHash.GetHashCode() : 0); hashCode = (hashCode * 397) ^ BlockNumber.GetHashCode(); hashCode = (hashCode * 397) ^ Gas.GetHashCode(); hashCode = (hashCode * 397) ^ GasPrice.GetHashCode(); hashCode = (hashCode * 397) ^ GasUsed.GetHashCode(); hashCode = (hashCode * 397) ^ Nonce.GetHashCode(); hashCode = (hashCode * 397) ^ Confirmations.GetHashCode(); hashCode = (hashCode * 397) ^ (Input != null ? Input.GetHashCode() : 0); return(hashCode); } }
public CallResult <List <ShippingMethodViewModel> > GetShippingOptionsModel(IUnitOfWork db, ITime time, ILogService log, IShipmentApi rateProvider, IShippingService shippingService, IWeightService weightService) { var result = new CallResult <List <ShippingMethodViewModel> >(); if (String.IsNullOrEmpty(OrderID)) { result.Status = CallStatus.Fail; result.Message = "Empty Order Id"; return(result); } var fromAddress = FromAddress.GetAddressDto(); var toAddress = ToAddress.GetAddressDto(); if (AddressHelper.IsEmpty(fromAddress) || AddressHelper.IsEmpty(toAddress)) { result.Status = CallStatus.Fail; result.Message = "Empty from/to address"; } var orders = db.ItemOrderMappings.GetFilteredOrdersWithItems(weightService, new OrderSearchFilter() { Market = MarketType.None, EqualOrderNumber = OrderID, IgnoreBatchFilter = true, IncludeNotify = false, UnmaskReferenceStyles = false, IncludeSourceItems = true, }); if (!orders.Any()) { result.Status = CallStatus.Fail; result.Message = "Cannot find order Id"; return(result); } //NOTE: no need to use Items from model, we always buy label for all items, only needs a custom weight var orderItems = OrderHelper.BuildAndGroupOrderItems(orders.SelectMany(o => o.Items).ToList()); orderItems = OrderHelper.GroupBySourceItemOrderId(orderItems); var sourceOrderItems = OrderHelper.BuildAndGroupOrderItems(orders.SelectMany(o => o.SourceItems).ToList()); sourceOrderItems = OrderHelper.GroupBySourceItemOrderId(sourceOrderItems); var shipDate = db.Dates.GetOrderShippingDate(null); var mainOrder = orders.FirstOrDefault(); result = MailViewModel.GetShippingOptionsWithRate(db, log, time, rateProvider, shippingService, fromAddress, toAddress, shipDate, WeightLb ?? 0, (decimal)(WeightOz ?? 0), new ItemPackageDTO() { PackageLength = PackageLength, PackageWidth = PackageWidth, PackageHeight = PackageHeight, }, 0, new OrderRateInfo() { OrderNumber = mainOrder.OrderId, Items = orderItems, SourceItems = sourceOrderItems, EstimatedShipDate = ShippingUtils.AlignMarketDateByEstDayEnd(mainOrder.LatestShipDate, (MarketType)mainOrder.Market), TotalPrice = orders.Sum(o => o.TotalPrice), Currency = mainOrder.TotalPriceCurrency, }); return(result); }
// public EMailResponseObjectModel(string hostName, int port) // { // mailMessageToSend = new MailMessage(); // smtpClient = new SmtpClient(hostName, port); // } // public void SendMessage(MailMessage message) // { // smtpClient.SendAsync(message, message.GetHashCode().ToString()); // } // public void SendMessage(string from, string to, string subject, string message) // { // MailAddress fromMailAddr; // MailAddress toMailAddr; // MailMessage mailMessage; // // if(from.IndexOf(',') != -1) // { // string fromAddr = from.Remove(from.IndexOf(','),from.Length); // string fromAddrDisplayAs = from.Remove(0,from.IndexOf(',')); // fromMailAddr = new MailAddress(fromAddr, // fromAddrDisplayAs, // System.Text.Encoding.UTF8); // } // else // { // fromMailAddr = new MailAddress(from, from, System.Text.Encoding.UTF8); // } // // toMailAddr = new MailAddress(to); // // mailMessage = new MailMessage(fromMailAddr.Address,toMailAddr.Address, subject, message); // mailMessage.BodyEncoding = Encoding.UTF8; // mailMessage.SubjectEncoding = Encoding.UTF8; // // smtpClient.UseDefaultCredentials = useDefaultCredentials; // // if(smtpCredentials != null) // { // smtpClient.Credentials = smtpCredentials; // } // // smtpClient.SendAsync(mailMessage, mailMessage.GetHashCode().ToString()); // // } /// <summary> /// /// </summary> public async void SendMessage() { try{ smtpClient = new SmtpClient(this.SMTPServerName, this.PortNumber); smtpClient.SendCompleted += (s, e) => { if (e.Error != null) { LogWriter.CreateLogEntry(string.Format("{0}\n{1}", e.Error.Message, e.Error.InnerException != null ? e.Error.InnerException.Message : "")); } //smtpClient.Dispose(); //mailMessageToSend.Dispose(); }; MailAddress fromMailAddr; MailAddress toMailAddr; MailMessage mailMessage = new MailMessage(); if (FromAddress.IndexOf(',') != -1) { string fromAddr = FromAddress.Remove(FromAddress.IndexOf(','), FromAddress.Length); string fromAddrDisplayAs = FromAddress.Remove(0, FromAddress.IndexOf(',')); fromMailAddr = new MailAddress(fromAddr, fromAddrDisplayAs, System.Text.Encoding.UTF8); } else { fromMailAddr = new MailAddress(FromAddress, FromAddress, System.Text.Encoding.UTF8); } mailMessage.From = fromMailAddr; string[] receipents = ToAddress.Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); if (this.UseDefaultCredentials) { smtpClient.UseDefaultCredentials = this.UseDefaultCredentials; } else { smtpClient.UseDefaultCredentials = this.UseDefaultCredentials; smtpClient.Credentials = new NetworkCredential(this.SMTPCredentials.UserName, this.SMTPCredentials.SecurePassword); } smtpClient.EnableSsl = this.IsSSLEnabled; smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network; foreach (string receipent in receipents) { if (receipent.IndexOf(',') != -1) { string toAddr = receipent.Remove(receipent.IndexOf(','), receipent.Length); string toAddrDisplayAs = receipent.Remove(0, receipent.IndexOf(',')); toMailAddr = new MailAddress(toAddr, toAddrDisplayAs, System.Text.Encoding.UTF8); } else { toMailAddr = new MailAddress(receipent, receipent, System.Text.Encoding.UTF8); } mailMessage.To.Add(toMailAddr); } mailMessage.Body = MessageBody; mailMessage.Subject = Subject; mailMessage.BodyEncoding = Encoding.UTF8; mailMessage.SubjectEncoding = Encoding.UTF8; await smtpClient.SendMailAsync(mailMessage); } catch (Exception e) { LogWriter.CreateLogEntry(string.Format("{0}; {1}; {2}", DateTime.Now, e.Message, e.InnerException.Message)); } }
public void AddTo(string pToAddress) { ToAddress.Add(pToAddress); }
public void Send() { var message = new MailMessage(); var toAddresses = ToAddress.Split(';'); var ccAddresses = CCAddress.Split(';'); var bccaddresses = BccAddress.Split(';'); try { foreach (String address in toAddresses) { message.To.Add(address); } } catch (Exception ex) { Console.WriteLine("The To Address field contained bad input."); Console.WriteLine("A valid email address may only contain letters, numbers, an underscore, a dash, a period, or an @ symbol."); } try { foreach (String address in ccAddresses) { message.CC.Add(address); } } catch (Exception ex) { Console.WriteLine("The CC Address field contained bad input."); Console.WriteLine("A valid email address may only contain letters, numbers, an underscore, a dash, a period, or an @ symbol."); } try { foreach (String address in bccaddresses) { message.Bcc.Add(address); } } catch (Exception ex) { Console.WriteLine("The BCC Address field contained bad input."); Console.WriteLine("A valid email address may only contain letters, numbers, an underscore, a dash, a period, or an @ symbol."); } try { message.From = new MailAddress(FromAddress); } catch (Exception ex) { Console.WriteLine("The From Address field contained bad input."); Console.WriteLine("A valid email address may only contain letters, numbers, an underscore, a dash, a period, or an @ symbol."); } message.Subject = Subject; message.Body = MessageBody; message.IsBodyHtml = IsBodyHtml; client.Send(message); }
public void ClearTo() { ToAddress.Clear(); }
public async Task <AuthenticationResult> CustomerRegisterAsync(CustomUserRegistrationReqObj userRegistration) { try { var accountNumber = GeneralHelpers.GenerateRandomDigitCode(10); var existingUser = await _userManager.FindByEmailAsync(userRegistration.Email); if (existingUser != null) { return(new AuthenticationResult { Status = new APIResponseStatus { IsSuccessful = false, Message = new APIResponseMessage { FriendlyMessage = "User with this email address already exist" } } }); } var user = new ApplicationUser { Email = userRegistration.Email, UserName = userRegistration.Email, PhoneNumber = userRegistration.PhoneNo, FirstName = userRegistration.FirstName, LastName = userRegistration.LastName, Address = userRegistration.Address, CustomerTypeId = userRegistration.CustomerTypeId, ApprovalStatusId = 1, SecurityAnswered = userRegistration.SecurityAnswered, QuestionId = userRegistration.QuestionId }; var createdUser = await _userManager.CreateAsync(user, userRegistration.Password); var customer = new credit_loancustomer { Email = userRegistration.Email, UserIdentity = user.Id, PhoneNo = userRegistration.PhoneNo, FirstName = userRegistration.FirstName, LastName = userRegistration.LastName, Address = userRegistration.Address, CustomerTypeId = userRegistration.CustomerTypeId, CASAAccountNumber = accountNumber, ApprovalStatusId = 1, ProfileStatus = 0, Active = true, Deleted = false, CreatedBy = user.Email, CreatedOn = DateTime.Now, RegistrationSource = "Website" }; _dataContext.credit_loancustomer.Add(customer); _dataContext.SaveChanges(); if (!createdUser.Succeeded) { return(new AuthenticationResult { Status = new APIResponseStatus { IsSuccessful = false, Message = new APIResponseMessage { FriendlyMessage = createdUser.Errors.Select(x => x.Description).FirstOrDefault(), } } }); } var custCode = ConfirmationCode.Generate(); var successful = await CustomerSendAndStoreConfirmationCode(custCode, user.Email); var accountId = user.Id; var name = user.FirstName; var baseUrl = _configuration.GetValue <string>("FrontEndUrl:webUrl"); var url = baseUrl + "/#/auth/activate-account/" + accountId + ""; var content1 = "Welcome to GOS Credit! There's just one step before you get to complete your customer account registration. Verify you have the right email address by clicking on the button below."; var content2 = "Once your account creation is completed, your can explore our services and have a seamless experience."; var body = GeneralHelpers.MailBody(name, url, content1, content2); var addresses = new ToAddress { name = user.FirstName + " " + user.LastName, address = user.Email }; var addressList = new List <ToAddress> { addresses }; var mailObj = new MailObj { subject = "Email Verification", content = body, toAddresses = addressList, fromAddresses = new List <FromAddress> { }, sendIt = true, saveIt = false }; var res = _identityServer.SendMail(mailObj); return(new AuthenticationResult { Status = new APIResponseStatus { IsSuccessful = true, CustomToken = custCode, } }); } catch (Exception ex) { #region Log error var errorCode = ErrorID.Generate(4); _logger.Error($"ErrorID : {errorCode} Ex : {ex?.Message ?? ex?.InnerException?.Message} ErrorStack : {ex?.StackTrace}"); return(new AuthenticationResult { Status = new APIResponseStatus { Message = new APIResponseMessage { FriendlyMessage = "Error occured!! Please try again later", MessageId = errorCode, TechnicalMessage = $"ErrorID : {errorCode} Ex : {ex?.Message ?? ex?.InnerException?.Message} ErrorStack : {ex?.StackTrace}" } } }); #endregion } }
private void LogMessage() { #if ActiveRecord if (!BewebData.TableExists("MailLog")) { new Sql("CREATE TABLE [dbo].[MailLog]([MailLogID] [int] IDENTITY(1,1) NOT NULL, [EmailTo] [nvarchar](150) NULL, [EmailSubject] [nvarchar](150) NULL, [Result] [nvarchar](250) NULL, [DateSent] [datetime] NULL, [EmailFrom] [nvarchar](150) NULL, CONSTRAINT [MailLog_PK] PRIMARY KEY NONCLUSTERED ([MailLogID] ASC))").Execute(); } if (!BewebData.FieldExists("MailLog", "DateSent")) { new Sql("ALTER TABLE [dbo].[MailLog] add [DateSent] [datetime] NULL").Execute(); } if (!BewebData.FieldExists("MailLog", "EmailTo")) { new Sql("ALTER TABLE [dbo].[MailLog] add [EmailTo] [nvarchar](150) NULL").Execute(); } if (!BewebData.FieldExists("MailLog", "EmailFrom")) { new Sql("ALTER TABLE [dbo].[MailLog] add [EmailFrom] [nvarchar](150) NULL").Execute(); } if (!BewebData.FieldExists("MailLog", "EmailFromName")) { new Sql("ALTER TABLE [dbo].[MailLog] add [EmailFromName] [nvarchar](150) NULL").Execute(); } if (!BewebData.FieldExists("MailLog", "EmailToName")) { new Sql("ALTER TABLE [dbo].[MailLog] add [EmailToName] [nvarchar](150) NULL").Execute(); } if (!BewebData.FieldExists("MailLog", "EmailCC")) { new Sql("ALTER TABLE [dbo].[MailLog] add [EmailCC] [nvarchar](250) NULL").Execute(); } if (!BewebData.FieldExists("MailLog", "DateViewTracked")) { new Sql("ALTER TABLE [dbo].[MailLog] add [DateViewTracked] [datetime] NULL").Execute(); } if (!BewebData.FieldExists("MailLog", "TrackingGUID")) { new Sql("ALTER TABLE [dbo].[MailLog] add [TrackingGUID] [nvarchar](50) NULL").Execute(); } if (MailLogFullText) { if (!BewebData.FieldExists("MailLog", "EmailBodyPlain")) { new Sql("ALTER TABLE [dbo].[MailLog] add [EmailBodyPlain] [nvarchar](max) NULL").Execute(); } if (!BewebData.FieldExists("MailLog", "EmailBodyHtml")) { new Sql("ALTER TABLE [dbo].[MailLog] add [EmailBodyHtml] [nvarchar](max) NULL").Execute(); } } var maillog = new ActiveRecord("MailLog", "MailLogID"); maillog["DateSent"].ValueObject = DateTime.Now; maillog["EmailFromName"].ValueObject = FromName.Left(150); maillog["EmailFrom"].ValueObject = FromAddress.Left(150); maillog["EmailToName"].ValueObject = ToName.Left(150); maillog["EmailTo"].ValueObject = ToAddress.Left(150); maillog["EmailSubject"].ValueObject = Subject.Left(150); maillog["EmailCC"].ValueObject = CC.Left(250); maillog["TrackingGUID"].ValueObject = trackingGuid; if (MailLogFullText) { maillog["EmailBodyPlain"].ValueObject = BodyPlain; maillog["EmailBodyHtml"].ValueObject = BodyHtml; } maillog["Result"].ValueObject = ErrorResult.Left(250) ?? "OK"; maillog.Save(); #endif }