コード例 #1
0
		public SendNotificationResult SendNotification(Core.Notification.Notification notification)
		{
			var retVal = new SendNotificationResult();

			SendGridMessage mail = new SendGridMessage();
			mail.From = new MailAddress(notification.Sender);
			mail.AddTo(notification.Recipient);
			mail.Subject = notification.Subject;
			mail.Html = notification.Body;

			var credentials = new NetworkCredential(_sendGridUserName, _sendGridPassword);
			var transportWeb = new Web(credentials);
			try
			{
				Task.Run(() => transportWeb.DeliverAsync(mail));
				retVal.IsSuccess = true;
			}
			catch (Exception ex)
			{
				retVal.ErrorMessage = ex.Message;
			}

			return retVal;
		}
		public SendNotificationResult SendNotification(Core.Notification.Notification notification)
		{
			var retVal = new SendNotificationResult();

			SendGridMessage mail = new SendGridMessage();
			mail.From = new MailAddress(notification.Sender);
			mail.AddTo(notification.Recipient);
			mail.Subject = notification.Subject;
			mail.Html = notification.Body;

			var userName = _settingsManager.GetSettingByName(sendGridUserNameSettingName).Value;
			var password = _settingsManager.GetSettingByName(sendGridPasswordSettingName).Value;

			var credentials = new NetworkCredential(userName, password);
			var transportWeb = new Web(credentials);
			try
			{
				transportWeb.DeliverAsync(mail).Wait();
				retVal.IsSuccess = true;
			}
			catch (Exception ex)
			{
				retVal.ErrorMessage = ex.Message;

				if (ex.InnerException is InvalidApiRequestException)
				{
					var apiEx = ex.InnerException as InvalidApiRequestException;
					if (apiEx.Errors != null && apiEx.Errors.Length > 0)
					{
						retVal.ErrorMessage = string.Join(" ", apiEx.Errors);
					}
				}
			}

			return retVal;
		}
コード例 #3
0
		public SendNotificationResult SendNotification(Core.Notification.Notification notification)
		{
			var retVal = new SendNotificationResult();

			SendGridMessage mail = new SendGridMessage();
			mail.From = new MailAddress(notification.Sender);
			mail.AddTo(notification.Recipient);
			mail.Subject = notification.Subject;
			mail.Html = notification.Body;

			var credentials = new NetworkCredential("*****@*****.**", "j8ddaANMU5Whzcu");
			var transportWeb = new Web(credentials);
			try
			{
				Task.Run(() => transportWeb.DeliverAsync(mail));
				retVal.IsSuccess = true;
			}
			catch (Exception ex)
			{
				retVal.ErrorMessage = ex.Message;
			}

			return retVal;
		}