Question Help with a setup

kwhelchel

Well-known member
Joined
Feb 28, 2020
Messages
53
Programming Experience
Beginner
OK I am stumped on this problem I am stuck on. In the image here the dashboard is my main and the sendmail is just a class. Now what I want to do is this. Dashboard is my configuration setup page, then the sendemail is the action that takes place from a bat file trigger. So can this be done first off and second what is needed ? aka what is it called for the procedure. Just need to be pointed in the right direction.

Thanks

send help.PNG
 
Anything can be done with software. The question is how much time, effort, and money you are willing to throw at the problem.

If you need your WinForms program to call the methods within your SendMail class, then just call the methods. Why even beat around the bush with a batch file to trigger the send mail. Anyway we really can't give you much advice because we can't see the code in your SendMail.cs nor in your Dashboard.cs. Please post the code from those files in code tags so that we can better advise you.
 
ok I can get the code but the trigger point for the send mail portion at this time comes from another software that triggers a batch file .

DashBoard:
namespace Versi_Send_Email
{
    public partial class DashBoard : Form
    {

        public DashBoard()
        {
            InitializeComponent();
        }
        
        private void DashBoard_Load(object sender, EventArgs e)
        {
            INIFile inif = new INIFile(@"c:\test\mailsettings.ini");
            sitetxtbox.Text = inif.Read("Properties", "site");
            emailtotxtbox.Text = inif.Read("Properties", "personto");
            cctotxtbox.Text = inif.Read("Properties", "ccto");
            bcctextbox.Text = inif.Read("Properties", "bcto");
        }


        private void updatebtn_Click(object sender, EventArgs e)
        {
 
            string siten = sitetxtbox.Text;
            sitetxtbox.Text = "siten";

            string personto = emailtotxtbox.Text;
            sitetxtbox.Text = "personto";

            string ccto = cctotxtbox.Text;
            sitetxtbox.Text = "ccto";

            string bcto = bcctextbox.Text;
            sitetxtbox.Text = "bcto";

            INIFile inif = new INIFile(@"c:\test\mailsettings.ini");

            inif.Write("Properties", "site", $"{siten}");
            inif.Write("Properties", "personto", $"{personto}");
            inif.Write("Properties", "ccto", $"{ccto}");
            inif.Write("Properties", "bcto", $"{bcto}");

 
            MessageBox.Show("Settings Have Been Updated");



        }


    }
}
class INIFile
{
    private string filePath;

    [DllImport("kernel32")]
    private static extern long WritePrivateProfileString(string section,
    string key,
    string val,
    string filePath);

    [DllImport("kernel32")]
    private static extern int GetPrivateProfileString(string section,
    string key,
    string def,
    StringBuilder retVal,
    int size,
    string filePath);

    public INIFile(string filePath)
    {
        this.filePath = filePath;
    }

    public void Write(string section, string key, string value)
    {
        WritePrivateProfileString(section, key, value.ToLower(), this.filePath);
    }

    public string Read(string section, string key)
    {
        StringBuilder SB = new StringBuilder(255);
        int i = GetPrivateProfileString(section, key, "", SB, 255, this.filePath);
        return SB.ToString();
    }

    public string FilePath
    {
        get { return this.filePath; }
        set { this.filePath = value; }
    }
}


send email portion:
namespace Versi_Send_Email
{
    class sendmail
    {
      //  string[] args = Environment.GetCommandLineArgs();

          //      foreach(string arg in Args)
        //    {
                // do stuff
      //      }

        private static Timer _timer = new Timer();

        public sendmail()
        {

            _timer.Tick += _timer_Tick;
            _timer.Interval = 5000; // 5 seconds
            _timer.Start();

        }
        void _timer_Tick(object sender, EventArgs e)
        {
            // Exit the App here ....
            Application.Exit();
            {
                INIFile inif = new INIFile(@"c:\test\mailsettings.ini");
                Console.WriteLine("The Value is:" + inif.Read("Properties", "site"));

                try
                {
                    MailMessage mail = new MailMessage();
                    SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
                    mail.From = new MailAddress("reports@versipos.com");
                    mail.To.Add(inif.Read("Properties", "personto"));
                    mail.CC.Add(inif.Read("Properties", "ccto"));
                    mail.Bcc.Add(inif.Read("Properties", "bcto"));
                    mail.Subject = inif.Read("Properties", "site") + " End Of Day Report";
                    //  mail.IsBodyHtml = false;
                    mail.IsBodyHtml = true;
                    mail.Body = "Greetings, attached is your End-of-Day Report.<br/> If you have any questions or concerns about this report please contact VersiPOS Client Services at support@versipos.com or by calling us at (800) 655-7349.<br/> + <img src='C:\\test\\1.jpg'/>";


                    System.Net.Mail.Attachment attachment;
                    attachment = new System.Net.Mail.Attachment(@"c:\test\zenni.pdf");
                    mail.Attachments.Add(attachment);

                    SmtpServer.Port = 587;
                    SmtpServer.Credentials = new System.Net.NetworkCredential("reports@versipos.com", "VersieR<GS5W");
                    SmtpServer.EnableSsl = true;

                    SmtpServer.Send(mail);
                    //  MessageBox.Show("mail Send");
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }

            }
        }

        class INIFile
        {
            private string filePath;

            [DllImport("kernel32")]
            private static extern long WritePrivateProfileString(string section,
            string key,
            string val,
            string filePath);

            [DllImport("kernel32")]
            private static extern int GetPrivateProfileString(string section,
            string key,
            string def,
            StringBuilder retVal,
            int size,
            string filePath);

            public INIFile(string filePath)
            {
                this.filePath = filePath;
            }

            public void Write(string section, string key, string value)
            {
                WritePrivateProfileString(section, key, value.ToLower(), this.filePath);
            }

            public string Read(string section, string key)
            {
                StringBuilder SB = new StringBuilder(255);
                int i = GetPrivateProfileString(section, key, "", SB, 255, this.filePath);
                return SB.ToString();
            }

            public string FilePath
            {
                get { return this.filePath; }
                set { this.filePath = value; }
            }
        }

    }

}
 
Back
Top Bottom