コード例 #1
0
 bool InsertEnquiry()
 {
     if (SendMail())
     {
         DBA.Contact contact = new DBA.Contact(ConfigurationManager.ConnectionStrings["DBConnection"].ToString());
         contact.Name = contactName.Text.Trim();
         contact.Email = email.Text.Trim();
         contact.Website = eurl.Text.Trim();
         contact.Message = commentsText.Text.Trim();
         if (contact.insertEnquiry(11))
         {
             return true;
         }
     }
     return false;
 }
コード例 #2
0
        bool SendMail()
        {
            DBA.Contact contact = new DBA.Contact(ConfigurationManager.ConnectionStrings["DBConnection"].ToString());
            DataTable dt = contact.getData(1);
            if (dt.Rows.Count > 0)
            {
                try
                {
                    var fromAddress = new MailAddress(dt.Rows[0]["Email"].ToString(), dt.Rows[0]["MailName"].ToString());
                    var toAddress = new MailAddress(email.Text.Trim());
                    string fromPassword = dt.Rows[0]["Password"].ToString();
                    string subject = "Enquiry";
                    string body = commentsText.Text.Trim();

                    var smtp = new SmtpClient
                    {
                        Host = "smtp.gmail.com",
                        Port = 587,
                        EnableSsl = true,
                        DeliveryMethod = SmtpDeliveryMethod.Network,
                        UseDefaultCredentials = false,
                        Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
                    };
                    using (var message = new MailMessage(fromAddress, toAddress)
                    {
                        Subject = subject,
                        Body = body
                    })
                    {
                        smtp.Send(message);
                    }
                    return true;
                }
                catch { }

            }
            return false;
        }