コード例 #1
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            mailMgr myMailmgr = new mailMgr();
            string  rtn       = myMailmgr.sendEmailViaGmail2("*****@*****.**", "*****@*****.**", "test"); // to notify user via eamil done mar 2020

            lblMsg.Text = rtn;
        }
コード例 #2
0
    protected void btnSendEmail_Click(object sender, EventArgs e)
    {
        mailMgr myMailMgr = new mailMgr();

        lblOuput.Text      = myMailMgr.sendEmailViaGmail();
        lblOuput.BackColor = System.Drawing.Color.Yellow;
    }
コード例 #3
0
        /// <summary>
        /// updated on Oct 30,2020
        ///
        /// to do :create a class to insert attached files to db and another one to inert attached files to folder
        /// </summary>
        protected void sendEmail2()
        {
            int    intSenderId = 111;
            string senderName  = Page.User.Identity.Name;

            senderName = (string.IsNullOrWhiteSpace(senderName)) ? "Admin"  : Page.User.Identity.Name;
            string rtn = "";

            if (string.IsNullOrEmpty(txtSubject.Text) || string.IsNullOrEmpty(txtBody.Text))
            {
                lblMsg.Text      = "Please fill Subject & email body";
                lblMsg.ForeColor = Color.Red;
                return;
            }

            InsertContactUs(); // to save email in database
            string senderEmail = txtSenderEmail.Text;

            using (mailMgr myMailMgr = new mailMgr())
            {
                myMailMgr.mySubject = txtSubject.Text + " " + senderEmail + ": " + senderName;
                myMailMgr.myBody    = txtBody.Text;
                if (fuAttachment.HasFile)
                {
                    foreach (HttpPostedFile file in fuAttachment.PostedFiles)
                    {
                        //1. get fileName
                        string fileName = Path.GetFileName(file.FileName);
                        //2. eihter save it to folder or
                        //. file.SaveAs(Server.MapPath("~/docEmailed/") + fileName);// to save attached files to a folder docEmailed
                        //3. send it to email or
                        //.  myMailMgr.Attachments.Add(new Attachment(file.InputStream, fileName)); // to attached files to email

                        // 4. save it to db
                        InsertDocuments(intSenderId);  // works but double entry
                    }
                    //.. rtn = myMailMgr.sendEmailViaGmail(fuAttachment);
                }
                else
                {
                    rtn = myMailMgr.sendEmailViaGmail();
                }
                lblMsg.Text      = rtn;
                lblMsg.ForeColor = Color.Green; // using System.Drawing above 2/2018
                lblMsg.BackColor = Color.Yellow;
            }
        }