protected void btnSubmit_Click(object sender, EventArgs e) { firstname = fnamebox.Text; lastname = lnamebox.Text; email = emailbox.Text; phone = phonebox.Text; address = addressbox.Text; city = citybox.Text; province = provincelist.SelectedValue.ToString(); postalcode = postalcodebox.Text; note = notebox.Text; CsCustomer newcustomer = new CsCustomer(customernum, firstname, lastname, address, city, province, postalcode, phone, email, note, registerdate, level); subject = "Thank you for registering, " + fnamebox.Text; content = @"<h2 style='color:blue;'> Hello " + fnamebox.Text + " ," + " Your account is created successfully. </h2> "; CsRegisterEmail newemail = new CsRegisterEmail(subject, content, email); try { ConnectionClass.RegistrationCustomer(newcustomer); ConnectionClass.SendRegisterEmail(newemail); ClientScript.RegisterStartupScript(GetType(), "message", "<script>alert('New Customer Registered successfully and Confirmation email sent out.');</script>"); ClearTextBoxes(Page); provincelist.ClearSelection(); } catch { Response.Write("<script type='text/javascript'>"); Response.Write("alert('please fill out all required fields ');"); Response.Write("</script>"); } finally { } }
public static void SendRegisterEmail(CsRegisterEmail cmail) { MailMessage msg = new MailMessage(); System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient(); try { msg.Subject = cmail.emailSubject; msg.Body = cmail.emailContent; msg.From = new MailAddress("*****@*****.**"); msg.To.Add(cmail.emailAddress); msg.IsBodyHtml = true; client.Host = "smtp.gmail.com"; System.Net.NetworkCredential basicauthenticationinfo = new System.Net.NetworkCredential("*****@*****.**", "1142311423"); client.Port = int.Parse("587"); //if using SSL 465 client.EnableSsl = true; client.UseDefaultCredentials = false; client.Credentials = basicauthenticationinfo; client.DeliveryMethod = SmtpDeliveryMethod.Network; client.Send(msg); //SmtpClient smtp = new SmtpClient("smtp.gmail.com", 465); //smtp.DeliveryMethod = SmtpDeliveryMethod.Network; ////to authenticate we set the username and password properites on the SmtpClient //smtp.Credentials = new NetworkCredential("*****@*****.**", "1142311423");//no need to mention here? //smtp.Send(msg); } finally { } }
protected void btnEmail_Click(object sender, EventArgs e) { email = lblCEmail.Text; subject = "Thank you for your purchase, " + lblCName.Text; string content1 = "<body style=\"text-align:center; background-color:#d8dfe5; padding-right:20%; padding-left:20%; \">"; string content2 = " <p style=\"font-size:20px;\"> Thank you for your purchase this time, Below is receipt details</p>" + "<br>"; string content3 = " <p style=\"font-size:14px; font-family:verdana; text-align:left;\"> Receipt # " + lblONum.Text + "</p>"; string content4 = GridViewToHtml(GridView1) + "<br>"; string content5 = "<div style=\"text-align:right; font-size:16px; \">"; string content6 = "Sales Quantity Total: " + lblTQty.Text + "<br>"; string content7 = "Net Total : " + lblTAmt.Text + "<br>"; string content8 = "Grand Total: " + lblGTotal.Text + "</div> <br>"; string content9 = "<p style=\"color:#405359; \"> For all returns, please bring this receipt with you </p>" + "</body>"; content = content1 + content2 + content3 + content4 + content5 + content6 + content7 + content8 + content9; CsRegisterEmail newemail = new CsRegisterEmail(subject, content, email); try { ConnectionClass.SendRegisterEmail(newemail); ClientScript.RegisterStartupScript(GetType(), "message", "<script>alert('email sent out.');</script>"); } catch { ClientScript.RegisterStartupScript(GetType(), "message", "<script>alert('error');</script>"); } finally { } }