Пример #1
0
    //CASE 1
    private string KirimEmail()
    {
        try
        {
            TBPengirimanEmail EmailKirim;
            TBStore           Store;

            using (DataClassesDatabaseDataContext db = new DataClassesDatabaseDataContext())
            {
                Store      = db.TBStores.FirstOrDefault();
                EmailKirim = db.TBPengirimanEmails.FirstOrDefault(item => item.TanggalKirim <= DateTime.Now);
            }

            if (EmailKirim != null)
            {
                Pengaturan.KirimEmail(Store.SMTPServer, Store.SMTPPort.Value, Store.SMTPUser, Store.SMTPPassword, Store.SecureSocketsLayer.Value, true, Store.SMTPUser, Store.Nama, EmailKirim.Tujuan, EmailKirim.Judul, EmailKirim.Isi);

                using (DataClassesDatabaseDataContext db = new DataClassesDatabaseDataContext())
                {
                    var EmailHapus = db.TBPengirimanEmails.FirstOrDefault(item => item.IDPengirimanEmail == EmailKirim.IDPengirimanEmail);

                    db.TBPengirimanEmails.DeleteOnSubmit(EmailHapus);
                    db.SubmitChanges();
                }

                return(JsonConvert.SerializeObject(new WebServiceResult
                {
                    EnumWebService = (int)EnumWebService.Success,
                    Pesan = "[BERHASIL DIKIRIM] EMAIL : " + EmailKirim.Judul + " - " + EmailKirim.Tujuan
                }, Formatting.Indented));
            }
            else
            {
                return(JsonConvert.SerializeObject(new WebServiceResult
                {
                    EnumWebService = (int)EnumWebService.NoAction,
                    Pesan = ""
                }, Formatting.Indented));
            }
        }
        catch (Exception ex)
        {
            LogError_Class Error = new LogError_Class(ex, "WebServiceTomahawk_KirimEmail");

            return(JsonConvert.SerializeObject(new WebServiceResult
            {
                EnumWebService = (int)EnumWebService.Exception,
                Pesan = ex.Message
            }, Formatting.Indented));
        }
    }
Пример #2
0
    protected void ButtonPercobaanEmail_Click(object sender, EventArgs e)
    {
        using (DataClassesDatabaseDataContext db = new DataClassesDatabaseDataContext())
        {
            Store_Class ClassStore = new Store_Class(db);

            var Store = ClassStore.Data();

            try
            {
                Pengaturan.KirimEmail(TextBoxSMTPServer.Text, TextBoxSMTPPort.Text.ToInt(), TextBoxSMTPUser.Text, TextBoxSMTPPassword.Text, CheckBoxSecureSocketsLayer.Checked, true, TextBoxEmail.Text, "WIT. Management System", TextBoxPercobaanEmail.Text, "Test Email - WIT Enterprise System", "This is a test message, your server is now available to send email");
                LiteralWarning.Text = Alert_Class.Pesan(TipeAlert.Success, "mengirim test email");
            }
            catch (Exception ex)
            {
                LogError_Class LogError_Class = new LogError_Class(ex, "ButtonPercobaanEmail_Click");
                LiteralWarning.Text = Alert_Class.Pesan(TipeAlert.Danger, "mengirim test email gagal");
            }
        }
    }