예제 #1
0
        public async void btnSend_Click(object sender, RoutedEventArgs e)
        {
            MailBuilder myMail = new MailBuilder();
            myMail.Html = problem.Text;
            myMail.Subject = subject.Text;

           
            myMail.To.Add(new MailBox(txtemail.Text));
            myMail.From.Add(new MailBox(subject.Text));
         

            IMail email = myMail.Create();

            try
            {
                using (Smtp smtp = new Smtp())
                {
                    await smtp.Connect("smtp.mail.yahoo.com.hk",465);
                    await smtp.UseBestLoginAsync("*****@*****.**", "tyive123");
                    await smtp.SendMessageAsync(email);
                    await smtp.CloseAsync();
                    MessageDialog msg = new MessageDialog("Mail has been sucessfully sent");
                    await msg.ShowAsync();
                }
            }
            catch (Exception ex)
            {
                MessageDialog msg = new MessageDialog("Mail has been sucessfully sent");
                msg.ShowAsync();
            }
        }
예제 #2
0
파일: SmtpTests.cs 프로젝트: DM-TOR/nhin-d
 public void SmtpGoodConnectTest()
 {
     Smtp smtp = new Smtp();
     //DirectGateway.South.Hobo.Lab 192.168.137.144
     bool success = smtp.TestConnection("10.110.3.242", 25);
     Assert.True(success);
 }
예제 #3
0
파일: Program.cs 프로젝트: Slesa/Playground
        static void Main()
        {
            IMail email = Mail
                .Html(@"<img src=""cid:lemon@id"" align=""left"" /> This is simple 
                        <strong>HTML email</strong> with an image and attachment")
                .Subject("Subject")
                .AddVisual("Lemon.jpg").SetContentId("lemon@id")
                .AddAttachment("Attachment.txt").SetFileName("Invoice.txt")
                .From(new MailBox("*****@*****.**", "Lemon Ltd"))
                .To(new MailBox("*****@*****.**", "John Smith"))
                .Create();

            email.Save(@"SampleEmail.eml");     // You can save the email for preview.

            using (Smtp smtp = new Smtp())      // Now connect to SMTP server and send it
            {
                smtp.Connect(_server);          // Use overloads or ConnectSSL if you need to specify different port or SSL.
                smtp.Ehlo();
                smtp.Login(_user, _password);   // You can also use: LoginPLAIN, LoginCRAM, LoginDIGEST, LoginOAUTH methods,
                // or use UseBestLogin method if you want Mail.dll to choose for you.
                smtp.SendMessage(email);

                smtp.Close();
            }

            // For sure you'll need to send more advanced emails, 
            // take a look at our templates support in SmtpTemplates sample.
        }
예제 #4
0
 public EMail(Smtp smtp)
 {
     _Smtp = smtp;
     _client.Credentials     = new NetworkCredential(_Smtp.Username, _Smtp.Password);
     _client.Port            = _Smtp.Port;
     _client.Host            = _Smtp.Server;
     _client.EnableSsl       = _Smtp.SSLSupport;
     _mailMessage.From       = new MailAddress(_Smtp.Username, _Smtp.Name);
     _mailMessage.IsBodyHtml = true;
 }
예제 #5
0
        public void Send_SpecifiedPickupDirectory()
        {
            Smtp.DeliveryMethod          = SmtpDeliveryMethod.SpecifiedPickupDirectory;
            Smtp.PickupDirectoryLocation = TempFolder;
            Smtp.Send("*****@*****.**", "*****@*****.**", "introduction", "hello");

            string[] files = Directory.GetFiles(TempFolder, "*");
            Assert.Equal(1, files.Length);
            Assert.Equal(".eml", Path.GetExtension(files[0]));
        }
예제 #6
0
        public configurationController(
            IApplicationLifetime applicationLifetime,
            IWritableOptions <General> general_options,
            IWritableOptions <Database> database_options,
            IWritableOptions <Smtp> smtp_options,
            IWritableOptions <Media> media_options,
            IWritableOptions <Features> features_options,
            IWritableOptions <Listing> listings_options,
            IWritableOptions <Authentication> authentication_options,
            IWritableOptions <Registration> registration_options,
            IWritableOptions <Aws> aws_options,
            IWritableOptions <Social> social_options,
            IWritableOptions <Contact> contact_options,
            IWritableOptions <Rechapcha> rechapcha_options,
            IOptions <General> generalSettings,
            IOptions <Smtp> smtpSettings,
            IOptions <Media> mediaSettings,
            IOptions <Features> featureSettings,
            IOptions <Listing> listingSettings,
            IOptions <Authentication> authenticationSettings,
            IOptions <Registration> registrationSettings,
            IOptions <Aws> awsSettings,
            IOptions <Social> socialSettings,
            IOptions <Contact> contactSettings,
            IOptions <Rechapcha> rechapchaSettings

            )
        {
            // writable injectors
            _database_options       = database_options;
            _general_options        = general_options;
            _smtp_options           = smtp_options;
            _media_options          = media_options;
            _features_options       = features_options;
            _listings_options       = listings_options;
            _authentication_options = authentication_options;
            _registration_options   = registration_options;
            _aws_options            = aws_options;
            _social_options         = social_options;
            _contact_options        = contact_options;
            _rechapcha_options      = rechapcha_options;
            ApplicationLifetime     = applicationLifetime;
            // readable injectors
            _generalSettings        = generalSettings.Value;
            _smtpSettings           = smtpSettings.Value;
            _mediaSettings          = mediaSettings.Value;
            _featureSettings        = featureSettings.Value;
            _listingSettings        = listingSettings.Value;
            _authenticationSettings = authenticationSettings.Value;
            _registrationSettings   = registrationSettings.Value;
            _awsSettings            = awsSettings.Value;
            _socialSettings         = socialSettings.Value;
            _contactSettings        = contactSettings.Value;
            _rechapchaSettings      = rechapchaSettings.Value;
        }
        private void btPrint_Click(object sender, EventArgs e)
        {
            String        PrinterName = "";
            PrinterDevice PrintTo     = PrinterDevice.Printer;
            Smtp          oSmtp       = new Smtp();

            switch (txtType.CheckedItem.DataValue.ToString())
            {
            case "Printer":
                PrintTo     = PrinterDevice.Printer;
                PrinterName = Global.OpenPrintDialog();
                if (PrinterName == "")
                {
                    return;
                }
                break;

            case "PDF":
                PrintTo       = PrinterDevice.PDF;
                oSmtp.Subject = "Purchase Orders " + DateTime.Now.ToShortDateString() + "   " + DateTime.Now.ToShortTimeString();
                oSmtp.To      = "<" + "*****@*****.**" + ">"; //this.eMail + ">";
                oSmtp.From    = "\"Signature Fundraising Customer Service\" <*****@*****.**>";

                String strTitle = "Purchase Order\n\r";

                oSmtp.Body = strTitle;


                break;

            case "Viewer":
                PrintTo = PrinterDevice.Viewer;
                break;
            }

            if (lvCustomers.Items.Count > 0)
            {
                foreach (Infragistics.Win.UltraWinListView.UltraListViewItem Item in lvCustomers.Items)
                {
                    if (oReceive.Find(Item.Tag.ToString()))
                    {
                        // if (PrintTo == PrinterDevice.PDF)
                        //     oSmtp.Attachment = oReceive.PrintPDF();
                        // else
                        oReceive.Print(PrintTo, PrinterName);
                    }
                }
                //if (PrintTo == PrinterDevice.PDF)
                //    oSmtp.Send();
            }



            this.Dispose();
        }
예제 #8
0
        private void buttonSend_Click(object sender, EventArgs e)
        {
            var mailbox = Mailbox;

            if (listViewMessages.CheckedItems.Count == 0)
            {
                MessageBox.Show(this, "Please select one or more messages to send.", "Send", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            if (String.IsNullOrEmpty(textBoxEmailAddress.Text) || !textBoxEmailAddress.Text.EndsWith("@decipha.com.au", StringComparison.CurrentCultureIgnoreCase))
            {
                MessageBox.Show(this, "Please enter a valid Decipha email address.", "Send", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            if (String.Compare((String)comboBoxFolder.SelectedItem, imapRoot, true) == 0 && IsServiceRunning() && mailbox.Enabled)
            {
                MessageBox.Show(this, "Cannot send messages from the root folder whilst Email Import service is running.", "Send", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            try
            {
                using (var imap = new Imap(mailbox.HostName, mailbox.Port, mailbox.UserName, mailbox.Password, (String)comboBoxFolder.SelectedItem))
                {
                    foreach (ListViewItem item in listViewMessages.CheckedItems)
                    {
                        var uid     = Convert.ToInt64(item.SubItems[7].Text);
                        var message = imap.DownloadMessage(uid);

                        // Attach to new mail message
                        var msg = message.ForwardAsAttachment();

                        // Setup the Mail Message properties
                        msg.From = EmailAddress.Parse("*****@*****.**");
                        msg.To.AddFromString(textBoxEmailAddress.Text);
                        msg.Subject = mailbox.Description;

                        // Send the Mail Message via SMTP
                        using (Smtp smtp = new Smtp())
                        {
                            smtp.SmtpServers.Add(Properties.Settings.Default.SmtpHost);
                            smtp.Message = msg;
                            smtp.Send();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.ToString(), "Send", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
예제 #9
0
 private async Task ConnectAsync(ISmtpConfig config)
 {
     try
     {
         await Smtp.ConnectAsync(config.Host, config.Port);
     }
     catch (Exception ex)
     {
         throw new SmtpNotConnectedException("Connection to smtp could not be made!", ex);
     }
 }
예제 #10
0
 private async Task AuthenticateAsync(ISmtpConfig config)
 {
     try
     {
         await Smtp.AuthenticateAsync(config.Mail, config.SenderPassword);
     }
     catch (Exception ex)
     {
         throw new SmtpNotAuthenticatedException("Could not authenticate at smtp server", ex);
     }
 }
예제 #11
0
        public static bool IsEnabled(string catalog)
        {
            Smtp smtp = GetSmtpConfig(catalog);

            if (smtp == null)
            {
                return(false);
            }

            return(smtp.Enabled);
        }
예제 #12
0
        // method for sending mail
        private void FireRecieveEvent(object body)
        {
            Smtp Mail = new Smtp();

            if (MessageReceived != null)
            {
                MessageReceived(this, new MessageEventArgs(body));
                string message = body.ToString();
                Mail.SendMail(message);
            }
        }
예제 #13
0
        public IActionResult BlogNotificationMailSend(int id)
        {
            try
            {
                var    setting     = settingRepository.GetById(1);
                var    emailList   = emailRegRepository.GetAll().Select(p => p.EmailAddress).ToList();
                var    blog        = blogRepository.GetById(id);
                string messageHtml = "" +
                                     "<div style='background-color:#F7F7F7;padding:5px;'>" +
                                     "<div style='background-color:#FFF;padding:5px;'>" +
                                     "<h3 style='text-align:center'>" + blog.Title + "</h3>" +
                                     "<p style='text-align:center'><img src='https://" + setting.SiteName + "/img/" + blog.ImageUrl + "' width='400px'/></p>" +
                                     "<p style='text-align:justify'>" + blog.Explanation + "...</p>" +
                                     "<a href='https://" + setting.SiteName + "/Home/Detail/" + blog.BlogId + "' style='text-decoration:none;text-align:center;display:block; background-color:#007bff;color:#fff;padding:10px 15px;border-radius:15px'>Makeleye Git</a>" +
                                     "<hr/>" +
                                     "<p>E-Posta aboneliğimizden çıkmak için <a href='https://" + setting.SiteName + "/Home/EmailCancellation'>buraya tıklayarak</a> ilgili adrese gidiniz.</p>" +
                                     "</div>" +
                                     "</div>";

                MailBuilder builder = new MailBuilder();

                builder.From.Add(new MailBox(setting.SMTPServerFrom, setting.SMTPServerFromName));
                builder.To.Add(new MailGroup("Undisclosed recipients"));

                foreach (string item in emailList)
                {
                    builder.Bcc.Add(new MailBox(item));
                }

                builder.Subject = blog.Title;
                builder.Html    = messageHtml;

                IMail email = builder.Create();

                using Smtp smtp = new Smtp();
                smtp.Connect(setting.SMTPServerHost, Convert.ToInt32(setting.SMTPServerPort)); // or ConnectSSL for SSL
                smtp.UseBestLogin(setting.SMTPServerUsername, setting.SMTPServerPassword);     // remove if not needed
                smtp.SendMessage(email);
                smtp.Close();

                blog.IsMailSend = true;
                if (blogRepository.UpdateBlog(blog))
                {
                    TempData["MailNotificationSuccess"] = "'" + blog.Title + "', bloğu için e-posta bildirimleri gönderildi.";
                }
            }
            catch
            {
                TempData["MailNotificationDanger"] = "E-Posta bildirimi gönderilirken bir hata oluştu!";
            }

            return(RedirectToAction("List"));
        }
예제 #14
0
        public void SendMessage()
        {
            try
            {
                XElement element = XElement.Load("MailSettings.xml");

                MailBuilder builder = new MailBuilder();
                //builder.Subject = String.Format("{0} - {1}", themeTxb.Text, SendMail.MailSettings.SenderName);
                builder.Subject = themeTxb.Text + " - " + element.Element("GeneralInformation").Element("senderName").Value;
                //builder.Subject = themeTxb.Text + " - " + SendMail.MailSettings.SenderName;
                builder.From.Add(new MailBox(element.Element("GeneralInformation").Element("email").Value, element.Element("GeneralInformation").Element("email").Value));
                //builder.From.Add(new MailBox(SendMail.MailSettings.Email));
                builder.To.Add(new MailBox(whomTxb.Text));
                builder.Text = contentTxb.Text;
                if (attachBtnFlag == true)
                {
                    foreach (var i in pathFileName)
                    {
                        builder.AddAttachment(i);
                    }
                }

                IMail email = builder.Create();

                using (Smtp smtp = new Smtp())
                {
                    smtp.ConnectSSL(element.Element("SendingMail").Element("sendingMail").Value);
                    //smtp.ConnectSSL(SendMail.MailSettings.SendingMail);
                    smtp.Configuration.EnableChunking = true;
                    smtp.UseBestLogin(element.Element("SendingMail").Element("sendingLogin").Value, element.Element("SendingMail").Element("sendingPassword").Value);
                    //smtp.UseBestLogin(SendMail.MailSettings.SendingLogin, SendMail.MailSettings.SendingPassword);
                    smtp.SendMessage(email);
                    MessageBox.Show("Електронний лист успішно надіслано!");
                }

                using (Imap imap = new Imap())
                {
                    imap.ConnectSSL(element.Element("ReceivingMail").Element("receivingMail").Value);
                    //imap.ConnectSSL(SendMail.MailSettings.ReceivingMail);
                    imap.UseBestLogin(element.Element("ReceivingMail").Element("receivingLogin").Value, element.Element("ReceivingMail").Element("receivingPassword").Value);
                    //imap.UseBestLogin(SendMail.MailSettings.ReceivingLogin, SendMail.MailSettings.ReceivingPassword);

                    CommonFolders folders = new CommonFolders(imap.GetFolders());
                    imap.UploadMessage(folders.Sent, email);

                    imap.Close();
                }
            }
            catch (IOException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
예제 #15
0
        public void CreateSmtp(Smtp smtp)
        {
            var count = _emailUnitOfWork.SmtpRepository.GetCount(x => x.Port == smtp.Port);

            if (count > 0)
            {
                throw new DuplicationException("Smtp configuration already exists", nameof(smtp.Port));
            }

            _emailUnitOfWork.SmtpRepository.Add(smtp);
            _emailUnitOfWork.Save();
        }
예제 #16
0
        private void btnTest_Click(object sender, EventArgs e)
        {
            TestMailForm testMailForm = new TestMailForm();

            if (testMailForm.ShowDialog(this) != DialogResult.OK)
            {
                return;
            }

            MailMessage msg = new MailMessage();

            msg.From = new EmailAddress(txtSenderMail.Text, txtSenderMail.Text);
            msg.To.Add(new EmailAddress(testMailForm.Recipient));
            msg.Subject       = testMailForm.Subject; // "[Notification Service] Test mail";
            msg.BodyPlainText = testMailForm.Body;    // "This is a test mail.";

            Smtp.LicenseKey = "MN200-B47C7EFF7C257CFF7C2E34E777B5-D2BD";
            Smtp smtp = new Smtp();

            if (chbUseSMTPServer.Checked)
            {
                SmtpServer server = new SmtpServer();
                server.Name        = txtServer.Text;
                server.Port        = (int)numPort.Value;
                server.AccountName = txtUserName.Text;
                server.Password    = txtPassword.Text;
                server.AuthMethods = MailBee.AuthenticationMethods.SaslLogin | MailBee.AuthenticationMethods.SaslPlain;
                smtp.SmtpServers.Add(server);
            }
            else
            {
                smtp.DnsServers.Autodetect();
            }

            try
            {
                smtp.Message = msg;
                if (smtp.Send())
                {
                    MessageBox.Show("Mail has been sent.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    string error = string.Format("Cannot send mail!\r\nError: {0}", smtp.GetErrorDescription());
                    MessageBox.Show(error, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                string error = string.Format("Cannot send mail!\r\nError: {0}", ex.Message);
                MessageBox.Show(error, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
예제 #17
0
        static void Main()
        {
            // Create test data for the template:
            Order order = new Order();

            order.OrderId      = 7;
            order.CustomerName = "John Smith";
            order.Currency     = "USD";
            order.Items.Add(new OrderItem {
                Name = "Yellow Lemons", Quantity = "22 lbs", Price = 149
            });
            order.Items.Add(new OrderItem {
                Name = "Green Lemons", Quantity = "23 lbs", Price = 159
            });

            // Load and render the template with test data:
            string html = Template
                          .FromFile("Order.template")
                          .DataFrom(order)
                          .PermanentDataFrom(DateTime.Now) // Year is used in the email footer/
                          .Render();

            // You can save the HTML for preview:
            File.WriteAllText("Order.html", html);

            // Create an email:
            IMail email = Mail.Html(Template
                                    .FromFile("Order.template")
                                    .DataFrom(order)
                                    .PermanentDataFrom(DateTime.Now)
                                    .Render())
                          .Text("This is text version of the message.")
                          .AddVisual("Lemon.jpg").SetContentId("lemon@id") // Here we attach an image and assign the content-id.
                          .AddAttachment("Attachment.txt").SetFileName("Invoice.txt")
                          .From(new MailBox("*****@*****.**", "Lemon Ltd"))
                          .To(new MailBox("*****@*****.**", "John Smith"))
                          .Subject("Your order")
                          .Create();

            // Send this email:
            using (Smtp smtp = new Smtp())              // Connect to SMTP server
            {
                smtp.Connect(_server);                  // Use overloads or ConnectSSL if you need to specify different port or SSL.
                smtp.UseBestLogin(_user, _password);    // You can also use: Login, LoginPLAIN, LoginCRAM, LoginDIGEST, LoginOAUTH methods,
                                                        // or use UseBestLogin method if you want Mail.dll to choose for you.

                SendMessageResult result = smtp.SendMessage(email);
                Console.WriteLine(result.Status);

                smtp.Close();
            }
        }
예제 #18
0
        public string SendEmail(Smtp smtp, string to, string subject, string body, List <Attachment> attachetments = null)
        {
            string result = string.Empty;

            try
            {
                string        footer   = "This e-mail is confidential and it is intended only for the addressees. Any review, dissemination, distribution, or copying of this message by persons or entities other than the intended recipient is prohibited. If you have received this e-mail in error, kindly notify us immediately by telephone or e-mail and delete the message from your system. The sender does not accept liability for any errors or omissions in the contents of this message which may arise as a result of the e-mail transmission.";
                string        note     = "Please do not reply to this email address.";
                string        htmlBody = $"<html><body><div style='border:30px solid ccc; border-radius:14px; padding:10px;'><p style='margin:0; font-size:22px;'>{subject}</p><p>{body}</p><hr style='margin:0;'/><p style='color:#148ecd;font-size:14px;'>{note}</p><p style='font-size:10px;'>{footer}</p></div></body></html>";
                AlternateView view     = AlternateView.CreateAlternateViewFromString(htmlBody, null, MediaTypeNames.Text.Html);

                using (var db = new UnitOfWork())
                {
                    var         fromAddress = new MailAddress(smtp.SMTPSender, smtp.SMTPSenderDisplayName);
                    var         toAddress   = new MailAddress(to, to);
                    MailMessage mailMessage = new MailMessage(fromAddress, toAddress);

                    mailMessage.IsBodyHtml = true;
                    mailMessage.Priority   = MailPriority.High;
                    mailMessage.Sender     = fromAddress;
                    mailMessage.To.Add(toAddress);
                    if (attachetments != null && attachetments.Any())
                    {
                        foreach (var attachment in attachetments)
                        {
                            mailMessage.Attachments.Add(attachment);
                        }
                    }

                    mailMessage.Subject = subject;
                    mailMessage.AlternateViews.Add(view);

                    Task.Factory.StartNew(() => {
                        SmtpClient smtpClient            = new SmtpClient(smtp.SMTP, smtp.SMTPPort);
                        smtpClient.UseDefaultCredentials = false;
                        var credential            = new NetworkCredential(smtp.SMTPSender, smtp.SMTPPassword);
                        smtpClient.Credentials    = credential;
                        smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
                        smtpClient.EnableSsl      = true;
                        smtpClient.Send(mailMessage);
                        smtpClient.Dispose();
                        mailMessage.Dispose();
                        return("success");
                    });
                    return("success");
                }
            }
            catch (Exception ex)
            {
                return("Failed to send mail due to <br/>" + ex);
            }
        }
예제 #19
0
 public SmtpModel(
     IWritableOptions <Application> writableApplication,
     IWritableOptions <Smtp> writableSmtp,
     ISmtpService smtpService)
 {
     this.smtpService         = smtpService;
     this.writableSmtp        = writableSmtp;
     this.writableApplication = writableApplication;
     application   = writableApplication.Value ?? new();
     Smtp          = writableSmtp.Value ?? new();
     password      = Smtp.Password;
     Smtp.Password = string.Empty;
 }
예제 #20
0
        public Task UpdateAsync(SmtpModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException("Smtp ArgumentNullException Update Async");
            }

            Smtp dto = AutoMapperGenericHelper <SmtpModel, Smtp> .Convert(model);

            _smtpRepository.Update(dto);

            return(Task.FromResult <object>(null));
        }
예제 #21
0
        public Task <object> InsertAsync(SmtpModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException("Smtp ArgumentNullException Insert Async");
            }

            Smtp dto = AutoMapperGenericHelper <SmtpModel, Smtp> .Convert(model);

            var id = _smtpRepository.Insert(dto);

            return(Task.FromResult <object>(id));
        }
예제 #22
0
        public static void Send(Smtp smtp, MailMessage message)
        {
            var client = GetSmtpClient(smtp);

            try
            {
                client.Send(message);
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("Could not send e-mail to " + message.To + ".\n" + message.Subject + "\n" + e.Message);
            }
        }
        public IActionResult GetEmailControlCode(EmailRegistration emailCancell)
        {
            string postResultString;
            int    messageNumber;
            var    emailCancelled = emailRegRepository.GetAll().Where(p => p.EmailAddress == emailCancell.EmailAddress);

            if (emailCancelled.Any())
            {
                if (ModelState.IsValid)
                {
                    var    setting     = settingRepository.GetById(1);
                    string messageHtml = "" +
                                         "<div style='background-color:#F7F7F7;padding:5px;'>" +
                                         "<div style='background-color:#FFF;padding:5px;'>" +
                                         "<p>Kontrol Kodunuz: " + emailCancelled.First().ControlCode + "</p>" +
                                         "</div>" +
                                         "</div>";

                    MailBuilder builder = new MailBuilder();

                    builder.From.Add(new MailBox(setting.SMTPServerFrom, setting.SMTPServerFromName));
                    builder.To.Add(new MailBox(emailCancell.EmailAddress));

                    builder.Subject = "Abonelik İptali İçin Kontrol Kodu";
                    builder.Html    = messageHtml;

                    IMail email = builder.Create();

                    using Smtp smtp = new Smtp();
                    smtp.Connect(setting.SMTPServerHost, Convert.ToInt32(setting.SMTPServerPort)); // or ConnectSSL for SSL
                    smtp.UseBestLogin(setting.SMTPServerUsername, setting.SMTPServerPassword);     // remove if not needed
                    smtp.SendMessage(email);
                    smtp.Close();

                    postResultString = "Kontrol kodu, e-posta adresinize gönderildi.";
                    messageNumber    = 2;
                }
                else
                {
                    postResultString = "Kontrol kodu gönderilirken bir hata oluştu! Lütfen daha sonra tekrar deneyiniz veya iletişime geçiniz.";
                    messageNumber    = 3;
                }
            }
            else
            {
                postResultString = "Girilen e-posta adresi için bir kayıt bulunamadı! Lütfen doğru bilgileri girdiğinizden emin olunuz.";
                messageNumber    = 1;
            }

            return(new JsonResult(new { message = postResultString, messageType = messageNumber }));
        }
예제 #24
0
 public void Dispose()
 {
     if (Smtp.IsConnected)
     {
         try
         {
             Smtp.Disconnect(true);
         }
         catch (ObjectDisposedException)
         {
         }
     }
     Smtp = null;
 }
예제 #25
0
        public void Create()
        {
            var smtp = new Smtp
            {
                SmtpProvider   = this.SmtpProvider,
                SmtpHostServer = this.SmtpHostServer,
                Port           = this.Port,
                EnableSsl      = this.EnableSsl,
                UserName       = this.UserName,
                Password       = this.Password
            };

            _smtpService.CreateSmtp(smtp);
        }
        private async void SendBtn_Click(object sender, RoutedEventArgs e)

        {
            MailBuilder myMail = new MailBuilder();

            myMail.Html = MsgText.Text;

            myMail.Subject = SubText.Text;

            await myMail.AddAttachment(AttachFile);

            myMail.To.Add(new MailBox(ToText.Text));

            myMail.From.Add(new MailBox(FromText.Text));



            IMail email = myMail.Create();



            try

            {
                using (Smtp smtp = new Smtp())

                {
                    await smtp.Connect("smtp.gmail.com", 587);

                    await smtp.UseBestLoginAsync(USER, PASSWORD);

                    await smtp.SendMessageAsync(email);

                    await smtp.CloseAsync();

                    MessageDialog msg = new MessageDialog("Mail has been sucessfully sent");

                    msg.ShowAsync();
                }
            }

            catch (Exception ex)

            {
                MessageDialog msg = new MessageDialog("Error in mail send");

                msg.ShowAsync();
            }
        }
예제 #27
0
 public void SendEmail(string toEmail, string subject, string body)
 {
     try
     {
         var smtpServer = SmtpServer;
         var smtp       = new Smtp();
         smtp.SmtpServers.Add(smtpServer);
         smtp.Message = PrepareMessage(toEmail, _configuration.SenderEmailAddress, subject, body);
         smtp.Send();
     }
     catch (MailBeeException ex)
     {
         throw new EmailException(ex.Message, ErrorCodes.OutgoingMailError);
     }
 }
예제 #28
0
        public static SmtpClient GetSmtpClient(Smtp smtp)
        {
            var credentials = !string.IsNullOrEmpty(smtp.Username) && !string.IsNullOrEmpty(smtp.Password)
                ? new NetworkCredential(smtp.Username, smtp.Password)
                : null;

            var client = new SmtpClient(smtp.Host, smtp.Port)
            {
                Credentials    = credentials,
                EnableSsl      = smtp.EnableSsl,
                DeliveryMethod = SmtpDeliveryMethod.Network,
            };

            return(client);
        }
예제 #29
0
        public static void Send(Smtp smtp, string from, string[] to, string subject, string body, bool isHtml = true)
        {
            var message = new MailMessage()
            {
                From         = new MailAddress(from),
                Subject      = subject,
                Body         = body,
                BodyEncoding = Encoding.UTF8,
                IsBodyHtml   = isHtml
            };

            to.ToList().ForEach(t => message.To.Add(t));

            Send(smtp, message);
        }
예제 #30
0
        public void Edit()
        {
            var smtp = new Smtp
            {
                Id             = this.Id,
                SmtpProvider   = this.SmtpProvider,
                SmtpHostServer = this.SmtpHostServer,
                Port           = this.Port,
                EnableSsl      = this.EnableSsl,
                UserName       = this.UserName,
                Password       = this.Password
            };

            _smtpService.EditSmtp(smtp);
        }
 public static string confirmarEquipo()
 {
     try
     {
         IB.Progress.BLL.MIEQUIPO miequipo = new IB.Progress.BLL.MIEQUIPO();
         miequipo.Update(((IB.Progress.Models.Profesional)HttpContext.Current.Session["PROFESIONAL"]).t001_idficepi);
         miequipo.Dispose();
         return(DateTime.Now.ToShortDateString());
     }
     catch (Exception ex)
     {
         Smtp.SendSMTP("Error al confirmar el equipo", ex.ToString());
         throw ex;
     }
 }
예제 #32
0
        public void Mail_versenden() {
            var mailAccess = MailAccessRepository.LoadFrom("mailfollowup.smtp.tests.mail.smtp.txt", Assembly.GetExecutingAssembly());
            var sut = new Smtp(mailAccess);

            var erinnerungsauftrag = new Erinnerungsauftrag {
                Mail = new Mail {
                    From = "*****@*****.**",
                    To = new[]{"hein@blöd.de"},
                    Subject = "Testmail",
                    Text = "Dies ist der Text der Mail."
                }
            };
            
            sut.Send(erinnerungsauftrag);
        }
예제 #33
0
        private void InitilaizeMailSender()
        {
            this.smtp = new Smtp();
            //
            var cfgMailRecipients = ConfigHelper.GetSetting("MailRecipients", "");

            this.mailRecipients = cfgMailRecipients.Split(';');
            if (this.mailRecipients.Length > 0)
            {
                foreach (var item in this.mailRecipients)
                {
                    this.logManager.Message.WriteTimeLine("Mail Recipients: {0}", item);
                }
            }
        }
예제 #34
0
        public void Dispose()
        {
            Log.Info("MailClient->Dispose()");

            try
            {
                if (Imap != null)
                {
                    if (Imap.IsConnected)
                    {
                        Imap.Disconnect(true, CancelToken);
                    }

                    Imap.Dispose();
                }

                if (Pop != null)
                {
                    if (Pop.IsConnected)
                    {
                        Pop.Disconnect(true, CancelToken);
                    }

                    Pop.Dispose();
                }

                if (Smtp != null)
                {
                    if (Smtp.IsConnected)
                    {
                        Smtp.Disconnect(true, CancelToken);
                    }

                    Smtp.Dispose();
                }

                Authenticated = null;
                SendMessage   = null;
                GetMessage    = null;

                StopTokenSource.Dispose();
            }
            catch (Exception ex)
            {
                Log.Error("MailClient->Dispose(Mb_Id={0} Mb_Addres: '{1}') Exception: {2}", Account.MailBoxId,
                          Account.EMail.Address, ex.Message);
            }
        }
예제 #35
0
 public void Contribute(ContributeModel model)
 {
     var userName = AppConfig.SmtpUserName;
     var content = string.Format("标题:{0}<br/>作者:{1}<p/>正文:{2}", model.Title, model.Author, model.Content);
     var message = new Message();
     message.Subject = "【新闻投稿】" + model.Title;
     message.From = userName;
     message.Charset = Encoding.GetEncoding("GB2312");
     message.BodyHtml = content;
     message.To.Add(AppConfig.ContributeSendTo);
     // 设置SMTP
     var smt = new Smtp
     {
         UserName = userName,
         Password = AppConfig.SmtpPassword,
         HostName = AppConfig.SmtpServer,
         Domain = AppConfig.SmtpDomain,
         Port = short.Parse(AppConfig.SmtpPort),
         Authentication = SmtpAuthentication.Login
     };
     smt.Send(message);
 }
예제 #36
0
        public bool SendResponse(IMailboxSettings mailboxSettings, Email email)
        {
            using (var client = new Smtp())
            {
                try
                {
                    client.ConnectSSL(mailboxSettings.OutboundServerAddress, mailboxSettings.OutboundServerPort);
                    client.LoginOAUTH2(email.FromAddress.Email, _oAuth2Authenticator.GetOAuth2AccessToken(email.FromAddress.Email));

                    return client.SendMessage(EmailMapper.MapToIMail(email)).Status == SendMessageStatus.Success;
                }
                catch (Exception ex)
                {
                    return false;
                }
            }
        }
예제 #37
0
파일: SmtpTests.cs 프로젝트: DM-TOR/nhin-d
        public void SmtpConnectTest()
        {
            Smtp smtp = new Smtp();
            Assert.Throws<SocketException>(() => smtp.TestConnection("localhostx", 25));

        }
        private async void btnPost_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            ProgBar.IsIndeterminate = true;

            EnableControl(false);

            if (txtBoxContent.Text != "")
            {
                string Content =
                    "From: " + txtBoxFrom.Text
                    + Environment.NewLine //New line
                    + "To: " + txtBoxTo.Text
                    + Environment.NewLine
                    + Environment.NewLine
                    + "Content: "
                    + Environment.NewLine
                    + txtBoxContent.Text
                    + Environment.NewLine
                    + Environment.NewLine
                    + "Sent from Nguyen An Ninh Confession App for Windows Phone :)";

                MailBuilder myMail = new MailBuilder();
                myMail.Text = Content;
                myMail.Subject = 
                    "New Confession from Windows Phone app - From "
                    + txtBoxFrom.Text 
                    + " - To "
                    + txtBoxTo.Text;
                //await myMail.AddAttachment(attachFile);
                myMail.To.Add(new MailBox("*****@*****.**"));
                myMail.From.Add(new MailBox("*****@*****.**"));

                IMail email = myMail.Create();

                try
                {
                    using (Smtp smtp = new Smtp())
                    {
                        await smtp.Connect("smtp.example.com", 25); //Change smtp address and port
                        await smtp.StartTLS();
                        await smtp.UseBestLoginAsync("*****@*****.**", "ExamplePassword"); //Change email credentials information
                        await smtp.SendMessageAsync(email);
                        await smtp.CloseAsync();

                        var msg = new MessageDialog("Your confession has been successfully sent!").ShowAsync();

                        ProgBar.IsIndeterminate = false;
                        EnableControl(true);
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.ToString()); //Use this to show Exception in the Output window.
                    var msgDialog = new MessageDialog("Please try again :(", "Failed to post").ShowAsync();
                    ProgBar.IsIndeterminate = false;
                    EnableControl(true);
                }
            }
            else
            {
                var msgDialog = new MessageDialog("Put something in before sending.", "Nothing to send").ShowAsync();
                EnableControl(true);
            }
        }
예제 #39
0
 //protected class ExchangePamater
 //{
 //    public System.Collections.Generic.List<String> EmailAddresses { get; set; }
 //    public String Subject { get; set; }
 //    public String Content { get; set; }
 //}
 /// </summary>
 /// <param name="mailAddress">目标邮箱地址</param>
 /// <param name="content">邮件内容</param>
 /// <param name="subject">邮件主题</param>
 /// <returns></returns>
 protected bool Send(string mailAddress, string content, string subject)
 {
     try
     {
         //smtp邮箱
         string smtpHost = System.Configuration.ConfigurationSettings.AppSettings.Get("MailServer");     //mail.163.com
         string userName = System.Configuration.ConfigurationSettings.AppSettings.Get("MailUserName");   //[email protected]
         string password = System.Configuration.ConfigurationSettings.AppSettings.Get("MailPassWord");   //...
         int smtpPort = 25;
         showwise.mail.Smtp Smtp = new Smtp(smtpHost, userName, password, smtpPort);// new Smtp(smtpHost, userName, password, smtpPort);                 //gang
         showwise.mail.MailMessage Message = new MailMessage(new showwise.mail.EmailAddress(System.Configuration.ConfigurationSettings.AppSettings.Get("MailFrom"), "百威"), new showwise.mail.EmailAddress(mailAddress));
         Message.Charset = "GB2312";
         Message.HtmlBody = content;
         Message.Subject = subject;
         Smtp.SendMail(Message);
         return true;
     }
     catch (Exception ex)
     {
         logger.LogError(ex.Message);
         return false;
     }
 }
예제 #40
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="folderName"></param>
 /// <param name="message"></param>
 public Boolean SaveMail(String folderName, Boolean draft, Smtp.SmtpMessage message)
 {
     var flag = "";
     if (draft == true)
     {
         flag = "\\Draft";
     }
     var rs = this.ExecuteAppend(folderName, message.GetRawText(), DateTimeOffset.Now, flag);
     return rs.Status == ImapCommandResultStatus.Ok;
 }