コード例 #1
0
        public List <TenantMailDetailsModel> GetTenantMailConfig(string ConStrings)
        {
            DataSet ds = new DataSet();
            List <TenantMailDetailsModel> tenantDetails = new List <TenantMailDetailsModel>();

            try
            {
                MySqlConnection conn = new MySqlConnection(ConStrings);

                if (conn != null && conn.State == ConnectionState.Closed)
                {
                    conn.Open();
                }
                MySqlCommand cmd = new MySqlCommand("SP_GetTenantMailerDetails", conn);
                cmd.CommandType = CommandType.StoredProcedure;
                MySqlDataAdapter da = new MySqlDataAdapter();
                da.SelectCommand = cmd;
                da.Fill(ds);
                if (ds != null && ds.Tables[0] != null)
                {
                    if (ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0)
                    {
                        foreach (DataRow dr in ds.Tables[0].Rows)
                        {
                            TenantMailDetailsModel obj = new TenantMailDetailsModel()
                            {
                                TenantID        = Convert.ToInt32(dr["TenantID"]),
                                SMTPHost        = dr["SMTPHost"] == System.DBNull.Value ? string.Empty : Convert.ToString(dr["SMTPHost"]),
                                SMTPPort        = dr["SMTPPort"] == System.DBNull.Value ? 0 : Convert.ToInt32(dr["SMTPPort"]),
                                AppID           = dr["AppID"] == System.DBNull.Value ? string.Empty : Convert.ToString(dr["AppID"]),
                                EmailID         = dr["EmailID"] == System.DBNull.Value ? string.Empty : Convert.ToString(dr["EmailID"]),
                                TenantStatusID  = dr["TenantStatusID"] == System.DBNull.Value ? 0 : Convert.ToInt32(dr["TenantStatusID"]),
                                ID              = dr["ID"] == System.DBNull.Value ? 0 : Convert.ToInt32(dr["ID"]),
                                IsActive        = dr["IsActive"] == System.DBNull.Value ? 0 : Convert.ToInt32(dr["IsActive"]),
                                EnabledSSL      = dr["EnabledSSL"] == System.DBNull.Value ? 0 : Convert.ToInt32(dr["EnabledSSL"]),
                                EmailUserID     = dr["EmailUserID"] == System.DBNull.Value ? string.Empty : Convert.ToString(dr["EmailUserID"]),
                                EmailSenderName = dr["EmailSenderName"] == System.DBNull.Value ? string.Empty : Convert.ToString(dr["EmailSenderName"]),
                                EmailSenderID   = dr["EmailSenderID"] == System.DBNull.Value ? string.Empty : Convert.ToString(dr["EmailSenderID"]),
                                EmailPassword   = dr["EmailPassword"] == System.DBNull.Value ? string.Empty : Convert.ToString(dr["EmailPassword"]),
                            };
                            tenantDetails.Add(obj);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                errorlogs.SendErrorToText(ex, ConStrings);
            }
            finally
            {
                if (ds != null)
                {
                    ds.Dispose();
                }
                conn.Close();
            }

            return(tenantDetails);
        }
コード例 #2
0
        //this is the mail function, it will connect to email server and will do all further process
        public DataTable getEmail(TenantMailDetailsModel tenantMailConfig, string ConStrings)
        {
            Pop3Client objPOP3Client = new Pop3Client();

            object[] objMessageParts;


            tenantMailConfig.SMTPHost = "pop.gmail.com";
            string strHostName = tenantMailConfig.SMTPHost, strPassword = tenantMailConfig.EmailPassword;

            strUserName = tenantMailConfig.EmailSenderID;
            int smtpPort = 995;

            int       intTotalEmail;
            DataTable dtEmail = new DataTable();

            try
            {
                if (objPOP3Client.Connected)
                {
                    objPOP3Client.Disconnect();
                }


                objPOP3Client.Connect(strHostName, smtpPort, true);

                //authenticate with server
                objPOP3Client.Authenticate(strUserName, strPassword);

                //get total email counts
                intTotalEmail = objPOP3Client.GetMessageCount();



                //put all mail content in this data table, so get blank table structure
                dtEmail = GetAllEmailStructure();

                //go through all emails
                for (int i = 1; i <= intTotalEmail; i++)
                {
                    objMessageParts = GetMessageContent(i, ref objPOP3Client, ConStrings);

                    if (objMessageParts != null && objMessageParts[0].ToString() == "0")
                    {
                        AddToDtEmail(objMessageParts, i, dtEmail, ConStrings);
                    }
                }
            }
            catch (Exception ex)
            {
                errorlogs.SendErrorToText(ex, ConStrings);
            }
            finally
            {
                if (objPOP3Client.Connected)
                {
                    objPOP3Client.Disconnect();
                }
            }
            return(dtEmail);
        }