Beispiel #1
0
    public static void SendmailWithIcsAttachment(string touser, string customer, string reference, string comments, DateTime followupdate, string custEmail, string MobileNo, string AssignTo, string title)
    {
        SQLProcs sqlobj       = new SQLProcs();
        string   AdminName    = "";
        string   AdminContact = "";

        try
        {
            //public string Location { get; set; }
            string Location = "";

            MailMessage msg     = new MailMessage();
            DataSet     dsAdmin = new DataSet();
            dsAdmin = sqlobj.SQLExecuteDataset("GetAdminDetails");
            if (dsAdmin != null && dsAdmin.Tables[0].Rows.Count > 0)
            {
                AdminName    = dsAdmin.Tables[0].Rows[0]["CompanyName"].ToString();
                AdminContact = dsAdmin.Tables[0].Rows[0]["ContactMobile"].ToString();
            }
            //Now we have to set the value to Mail message properties

            string tomail = "";

            DataSet dsemail = sqlobj.SQLExecuteDataset("SP_GetMailId",
                                                       new SqlParameter()
            {
                ParameterName = "@UserID", SqlDbType = SqlDbType.NVarChar, Value = touser.ToString()
            });

            if (dsemail.Tables[0].Rows.Count > 0)
            {
                tomail = dsemail.Tables[0].Rows[0]["StaffEmail"].ToString();
            }

            dsemail.Dispose();

            if (tomail.ToString() != "")
            {
                string strmcusername = "";
                string strmcpassword = "";
                string strmcfromname = "";

                DataSet dsmc = sqlobj.SQLExecuteDataset("SP_GetMailCredential");
                if (dsmc.Tables[0].Rows.Count > 0)
                {
                    strmcusername = dsmc.Tables[0].Rows[0]["username"].ToString();
                    strmcpassword = dsmc.Tables[0].Rows[0]["password"].ToString();
                    strmcfromname = dsmc.Tables[0].Rows[0]["sentbyuser"].ToString();
                }

                dsmc.Dispose();

                MailClass M = new MailClass();
                M.AppointMail(strmcusername, strmcfromname, tomail.ToString(), touser.ToString(), customer, reference, comments,
                              followupdate, strmcusername.ToString(), strmcpassword.ToString(), custEmail, AdminName, AdminContact, MobileNo, AssignTo, title);
            }
        }
        catch (Exception ex)
        {
            // CreateLogFiles Err = new CreateLogFiles();
            String[] contents = { ex.Message.ToString() };
            //System.IO.File.WriteAllLines(Server.MapPath("error.txt"), contents);
        }
    }