Exemplo n.º 1
0
        public void InsertError(Exception err, int refId)
        {
            string conn        = "Data Source=diyfe.org;Initial Catalog=MLB;Persist Security Info=True;User ID=jbt411;Password=ZigZag15";
            string queryString = "INSERT INTO [MLB].[dbo].[Error] ([RefId],[ErrorMethod],[ErrorText],[ErrorDate]) VALUES (@RefId,@ErrorMethod,@ErrorText,@ErrorDate)";

            using (System.Data.SqlClient.SqlConnection connection = new System.Data.SqlClient.SqlConnection(conn))
            {
                // Create the Command and Parameter objects.
                System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand(queryString, connection);
                command.Parameters.AddWithValue("@RefId", refId);
                if (err.Source == null)
                {
                    err.Source = "none";
                }
                command.Parameters.AddWithValue("@ErrorMethod", err.Source);

                command.Parameters.AddWithValue("@ErrorText", "Excpetion: " + err.Message + "</br>Inner Excpetion: " + err.InnerException);
                command.Parameters.AddWithValue("@ErrorDate", DateTime.Now);

                try
                {
                    var email  = EmailMessageFactory.GetErrorEmail(err);
                    var result = EmailClient.SendEmail(email);

                    connection.Open();
                    command.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    var email  = EmailMessageFactory.GetErrorEmail(ex);
                    var result = EmailClient.SendEmail(email);
                }
            }
        }
Exemplo n.º 2
0
        public ActionResult Send(Email email)
        {
            if (!ModelState.IsValid)
            {
                return(PartialView(email));
            }

            var sendEmail = new Email()
            {
                Body      = email.Body,
                Recipient = email.Recipient,
                Sender    = LoggedUser,
                SentDate  = DateTime.Now,
                Subject   = email.Subject
            };

            var err = EmailClient.SendEmail(sendEmail, UploadedFiles);

            if (err != null)
            {
                ModelState.AddModelError("", err);
                return(PartialView(sendEmail));
            }

            db.Users.Attach(sendEmail.Sender);
            db.Emails.Add(sendEmail);
            db.SaveChanges();
            return(PartialView(sendEmail));
        }
Exemplo n.º 3
0
        public void InsertError(Exception err, int refId, bool sendMail)
        {
            string conn        = System.Configuration.ConfigurationManager.ConnectionStrings["MainConnection"].ConnectionString;
            string queryString = "INSERT INTO [MLB].[dbo].[Error] ([RefId],[ErrorMethod],[ErrorText],[ErrorDate]) VALUES (@RefId,@ErrorMethod,@ErrorText,@ErrorDate)";

            using (System.Data.SqlClient.SqlConnection connection = new System.Data.SqlClient.SqlConnection(conn))
            {
                // Create the Command and Parameter objects.
                System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand(queryString, connection);
                command.Parameters.AddWithValue("@RefId", refId);
                command.Parameters.AddWithValue("@ErrorMethod", err.Source);
                command.Parameters.AddWithValue("@ErrorText", err.InnerException);
                command.Parameters.AddWithValue("@ErrorDate", DateTime.Now);

                try
                {
                    connection.Open();
                    command.ExecuteNonQuery();
                }
                catch (Exception ex)
                { }
            }

            if (sendMail)
            {
                var email  = EmailMessageFactory.GetErrorEmail(err);
                var result = EmailClient.SendEmail(email);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// The main entry point for the console application.
        /// </summary>
        /// <param name="args">The command line arguments</param>
        static void Main(string[] args)
        {
            // Get the settings from the App.Config file
            var loginUrl      = ConfigurationManager.AppSettings["LoginUrl"];
            var senderAddress = ConfigurationManager.AppSettings["SenderAddress"];

            // Create the mail object
            var email = EmailMessageFactory.GetWelcomeEmail(
                "*****@*****.**",
                "jdoe123",
                "John Doe",
                "nerdyp@ss",
                loginUrl,
                senderAddress);

            // Send the message
            var result = EmailClient.SendEmail(email);

            // Check the result
            if (result.Failed)
            {
                Console.WriteLine(result.Exception.Message);
            }
            else
            {
                Console.WriteLine("Sent mail:");
                Console.Write(result.Message.Body);
            }

            Console.WriteLine("Press any key to exit");
            Console.ReadLine();
        }
Exemplo n.º 5
0
        public bool MakePurchase(PurchaseRequest purchaseRequest)
        {
            Device device = new Device
            {
                DeviceType = purchaseRequest.DeviceType
            };

            _sendesContext.Device.Add(device);
            _sendesContext.SaveChanges();
            int deviceId = device.Id; // id is created after saveChanges is called

            System.Console.WriteLine(deviceId);
            MailMessage message = new MailMessage();

            message.To.Add(purchaseRequest.EmailAddress);
            message.Subject = "Purchase confirmation";
            message.Body    = $"Your device ID is {deviceId} {Environment.NewLine}If you have not done so already, please create account. After your account has been created, head over to the dashboard and use the device ID to register your new device.";
            _emailClient.SendEmail(message);
            return(true);
        }
Exemplo n.º 6
0
        public async void can_send_email()
        {
            string       body    = "<html><body>Some text</body></html>";
            string       subject = "DotNet SDK unit tests";
            EmailAddress from    = new EmailAddress("Developers", "*****@*****.**");
            EmailAddress to      = new EmailAddress("Test", "*****@*****.**");

            EmailAddress[]    toAddresses = new EmailAddress[] { to };
            EmailAttachment[] attachments = null;
            string            messageId   = await EmailClient.SendEmail(body, attachments, from, toAddresses, null, null, subject, Model.TenantName.ONEBLINK_TEST);

            Assert.NotNull(messageId);
        }
 public ActionResult AddOrEditUK(Customer customerModel)
 {
     try
     {
         EmailClient objEmail  = new EmailClient();
         Encryption  objDeco   = new Encryption();
         String      email     = objDeco.EmailEncryption(customerModel.email);
         String      htmlEmail = objEmail.GetMessageHTML(email, "UK");
         objEmail.SendEmail(htmlEmail, customerModel.email);
         ModelState.Clear();
         ViewBag.SuccessMessage = "You will receive a Confirmation Email.";
     }
     catch (Exception e)
     {
         ViewBag.ErrorMessage = e.Message;
     }
     return(View("AddOrEditUK", new Customer()));
 }
        public async Task <ActionResult> CreateAsync(CreateUserViewModel vm)
        {
            if (ModelState.IsValid)
            {
                var newUser = UserStore.CreateUser();
                newUser.CompanyId = CompanyId;
                newUser.UserName  = vm.UserName;
                newUser.Email     = vm.Email;

                try
                {
                    var created = await userManager.CreateAsync(newUser, GenerateTempPassword(7));

                    if (created.Succeeded)
                    {
                        await userManager.AddToRoleAsync(newUser.Id, "User");

                        // Send confirmation email.
                        var code = await userManager.GenerateEmailConfirmationTokenAsync(newUser.Id);

                        var url = Url.Action("ActivateAccount", "Security", new { area = "", userId = newUser.Id, code = code }, protocol: Request.Url.Scheme);
                        using (var emailClient = new EmailClient())
                        {
                            await emailClient.SendEmail("Confirm PM Account", "<p>Please confirm your account by clicking this link: <a href=\"" + url + "\">link</a></p>", newUser.Email);
                        }

                        // TODO: PUT THIS IN THE BASE CONTROLLER.
                        var users = await UserStore.GetUsersByCompanyIdAsync(CompanyId, this.ToNavPropertyString(nameof(IUserPoco.UserRoles), nameof(IUserRolePoco.Role)));

                        var usersVm = Mapper.Map <IEnumerable <UserPreviewViewModel> >(users);

                        Response.StatusCode = (int)HttpStatusCode.OK;
                        return(Json(new { success = true, responseText = "User is created successfuly.", html = this.RenderView("_UsersList", usersVm) }, JsonRequestBehavior.AllowGet));
                    }
                }
                catch (Exception ex)
                {
                    SetErrorResponse(HttpStatusCode.InternalServerError, "Something went wrong");
                }
            }

            Response.StatusCode = (int)HttpStatusCode.BadRequest;
            return(PartialView("_NewUserModal", vm));
        }
        /// <summary>
        /// Log a support request with the support provider, including the log file
        /// and supplied problem description
        /// </summary>
        /// <param name="supportEmailAddress">The email address to send the support request to</param>
        /// <param name="logfileAppenderName">The name of the log file appender as configured in the log4net configuration for the application</param>
        /// <param name="problemDescription">The user described problem description</param>
        /// <param name="stepsToReproduce">The user described steps to reproduce the issue</param>
        /// <param name="allFiles">Flag indicating if all log files should be extracted</param>
        public void LogSupportRequest(string supportEmailAddress, string logfileAppenderName, string problemDescription, string stepsToReproduce, bool allFiles)
        {
            var emailClient = new EmailClient();

            emailClient.FromAddress = new MailAddress(WinUtils.CurrentUserEmailAddress(), WinUtils.GetCurrentUserNameWithoutDomain());

            var messageBody = string.Format("Problem Description:\n\n{0}\n\n\nSteps to Reproduce:\n\n{1}\n\n", problemDescription, stepsToReproduce);

            MailMessage message = emailClient.CreateMessage("NOES Support Request from " + System.Environment.MachineName, messageBody);

            var files = Log4NetExtensions.GetLogFiles(logfileAppenderName, allFiles);

            // Initialise any progress listeners
            if (InitialiseSupportProgress != null)
            {
                var e = new InitialiseProgressEventArgs()
                {
                    ElementCount = files.Count
                };
                InitialiseSupportProgress(this, e);
            }
            foreach (var logfilePath in files)
            {
                var logfileName = Path.GetFileName(logfilePath);
                using (var stream = new FileStream(logfilePath, FileMode.Open))
                {
                    Attachment logfile = emailClient.CreateGzipAttachment(stream, logfileName + ".gz", EmailClient.ApplicationGzip);
                    message.Attachments.Add(logfile);
                }
                // Update any progress listeners
                if (UpdateSupportProgress != null)
                {
                    UpdateSupportProgress(this, EventArgs.Empty);
                    Application.DoEvents();
                }
            }

            var supportAddress = new MailAddress(supportEmailAddress);

            emailClient.SendEmail(message, supportAddress);
        }
Exemplo n.º 10
0
        public ActionResult SendContactEmail(ContactMailModel model)
        {
            var data = new object();

            try
            {
                var email  = EmailMessageFactory.GetContactEmail(model);
                var result = EmailClient.SendEmail(email);

                if (!String.IsNullOrEmpty(model.NewsLetter))
                {
                    try
                    {
                        NewsLetter letter = new NewsLetter()
                        {
                            Email       = model.Email,
                            DateCreated = DateTime.Now
                        };
                        using (var db = new DIYFE.EF.DIYFEEntities())
                        {
                            db.NewsLetters.Add(letter);
                            db.SaveChanges();
                        }
                    }
                    catch (Exception ex)
                    {
                        data = new { success = false, message = "Message Was Sent...but failed to join news letter." };
                        return(Json(data));
                    }
                }
            }
            catch (Exception ex)
            {
                data = new { success = false, message = "Failed to send comment.  Please trying contacting us directly." };
                return(Json(data));
            }

            data = new { success = true };

            return(Json(data));
        }
Exemplo n.º 11
0
        public ActionResult SendContactEmail(string firstName, string lastName, string email, string message)
        {
            var data = new object();

            var emailBody = EmailMessageFactory.GetWebContact(
                firstName + " " + lastName, email, message);

            // Send the message
            var result = EmailClient.SendEmail(emailBody);

            // Check the result
            if (result.Failed)
            {
                data = new { success = false, message = "Failed to send email contact.  Please give us a call." };
                return(Json(data));
            }
            else
            {
                data = new { success = true };
            }

            return(Json(data));
        }
Exemplo n.º 12
0
 public void Send_An_Email_using_AWS_SES()
 {
     EmailClient.SendEmail("*****@*****.**", "Jubin Jose", "*****@*****.**",
                           "<aws-smtp-username>", "<aws-smtp-password>",
                           "AWS Test", "<b>Hello</b>");
 }