Exemplo n.º 1
0
    private void SendEmailMessage(string Message)
    {
        try
        {
            SmtpSettings objSmtp = new SmtpSettings();
            DataSet dsSmtp = objSmtp.GetSmtpSettings();
            if (dsSmtp.Tables.Count > 0)
            {
                if (dsSmtp.Tables[0].Rows.Count > 0)
                {
                    SMTPProperties objSmtpProp = new SMTPProperties();
                    SMTPSendEMail objEmail = new SMTPSendEMail();

                    objSmtpProp.Server = dsSmtp.Tables[0].Rows[0][0].ToString();
                    objSmtpProp.Port = int.Parse(dsSmtp.Tables[0].Rows[0][1].ToString());
                    objSmtpProp.UserName = dsSmtp.Tables[0].Rows[0][2].ToString();
                    objSmtpProp.PassWord = dsSmtp.Tables[0].Rows[0][3].ToString();

                    if (txtEmailFrom.Text != "")
                        objSmtpProp.MailFrom = txtEmailFrom.Text;
                    else
                        objSmtpProp.MailFrom = dsSmtp.Tables[0].Rows[0][4].ToString();

                    objSmtpProp.MailTo = txtEmailTo.Text;
                    objSmtpProp.IsSSL = bool.Parse(dsSmtp.Tables[0].Rows[0][6].ToString());
                    objSmtpProp.IsHTML = bool.Parse(dsSmtp.Tables[0].Rows[0][7].ToString());

                    char mailPriority = char.Parse(dsSmtp.Tables[0].Rows[0][8].ToString());
                    switch (mailPriority)
                    {
                        case 'L': { objSmtpProp.MailPriority = SMTPProperties.Priority.Low; break; }
                        case 'H': { objSmtpProp.MailPriority = SMTPProperties.Priority.High; break; }
                        case 'N': { objSmtpProp.MailPriority = SMTPProperties.Priority.Normal; break; }
                    }

                    if (txtEmailSubject.Text != "")
                        objSmtpProp.MailSubject = txtEmailSubject.Text;
                    else
                        objSmtpProp.MailSubject = "Call Log";

                    if (txtEmailMessage.Text != "")
                        objSmtpProp.MailMessage = txtEmailMessage.Text + "<br/>" + Message;
                    else
                        objSmtpProp.MailMessage = Message;

                    MailResponse objMailResp = objEmail.SendEmail(objSmtpProp);
                    string str = "alert('" + objMailResp.StatusMessage + "');";
                    ScriptManager.RegisterStartupScript(imgBtnSendEmail, typeof(Page), "alert", str, true);
                }
            }
        }
        catch (Exception ex)
        {
            objNLog.Error("Error : " + ex.Message);
        }
    }
Exemplo n.º 2
0
    private void GetSmtpSettings()
    {
        SmtpSettings objSmtp = new SmtpSettings();
        DataSet dsSmtp = objSmtp.GetSmtpSettings();
        if (dsSmtp.Tables.Count > 0)
        {
            if (dsSmtp.Tables[0].Rows.Count > 0)
            {
                btnSmtpUpdate.Visible = true;
                btnSmtpSubmit.Visible = false;
                SMTPProperties objSmtpProp = new SMTPProperties();
                SMTPSendEMail objEmail = new SMTPSendEMail();

                if(dsSmtp.Tables[0].Rows[0][0]!= System.DBNull.Value)
                    txtSmtpServer.Text = dsSmtp.Tables[0].Rows[0][0].ToString();

                if (dsSmtp.Tables[0].Rows[0][1] != System.DBNull.Value)
                    txtSmtpPort.Text = dsSmtp.Tables[0].Rows[0][1].ToString();

                if (dsSmtp.Tables[0].Rows[0][2] != System.DBNull.Value)
                    txtSmtpUserID.Text = dsSmtp.Tables[0].Rows[0][2].ToString();

                if (dsSmtp.Tables[0].Rows[0][3] != System.DBNull.Value)
                    txtSmtpPassword.Text = dsSmtp.Tables[0].Rows[0][3].ToString();

                if (dsSmtp.Tables[0].Rows[0][4] != System.DBNull.Value)
                    txtMailFrom.Text = dsSmtp.Tables[0].Rows[0][4].ToString();

                if (dsSmtp.Tables[0].Rows[0][5] != System.DBNull.Value)
                    txtMailTo.Text = dsSmtp.Tables[0].Rows[0][5].ToString();

                if (dsSmtp.Tables[0].Rows[0][6] != System.DBNull.Value)
                    chkIsSSL.Checked = bool.Parse(dsSmtp.Tables[0].Rows[0][6].ToString());

                if (dsSmtp.Tables[0].Rows[0][7] != System.DBNull.Value)
                    chkIsHTML.Checked = bool.Parse(dsSmtp.Tables[0].Rows[0][7].ToString());

                char mailPriority='N';
                if (dsSmtp.Tables[0].Rows[0][8] != System.DBNull.Value)
                      mailPriority = char.Parse(dsSmtp.Tables[0].Rows[0][8].ToString());

                switch (mailPriority)
                {
                    case 'L': { ddlMailPriority.SelectedValue = "L"; break; }
                    case 'H': { ddlMailPriority.SelectedValue = "H"; break; }
                    case 'N': { ddlMailPriority.SelectedValue = "N"; break; }
                }
            }
        }
        else
        {
            btnSmtpSubmit.Visible = true;
            btnSmtpUpdate.Visible = false;
        }
    }