コード例 #1
0
 //bind data
 private void _subRebind()
 {
     ltv_main.DataSource = objNews.getNewsletter();
     ltv_main.DataBind();
     dtl_mainDL.DataSource = objLetter.getSendNewsletter();
     dtl_mainDL.DataBind();
 }
コード例 #2
0
    protected void subClick(object sender, EventArgs e)
    {
        var         allEmails = objEmail.getNewsletter();
        MailMessage message   = new MailMessage();

        foreach (var eachEmail in allEmails)
        {
            message.To.Add(eachEmail.email);
        }

        message.From = new MailAddress("*****@*****.**", "newsletter");

        //save images
        if (ful_attach.HasFile)
        {
            string file     = ful_attach.FileName.ToString();
            String filePath = "~/admin/img/newsletter/" + file;
            ful_attach.SaveAs(MapPath(filePath));

            //insert(send) data to database
            _strMessage(objNews.commitInsert(txt_subject.Text.ToString(), txt_message.Text.ToString(), filePath), "insert");

            //attach a file
            Attachment data = new Attachment(Server.MapPath("~/admin/img/newsletter/" + ful_attach.FileName.ToString()), MediaTypeNames.Application.Octet);
            message.Attachments.Add(data);
        }

        //setting from and to

        message.Subject = txt_subject.Text.ToString();
        message.Body    = txt_message.Text.ToString();

        ////attach a file
        //Attachment data = new Attachment(Server.MapPath("~/admin/img/newsletter/" + ful_attach.FileName.ToString()), MediaTypeNames.Application.Octet);
        //message.Attachments.Add(data);

        //send a newsletter
        SmtpClient client = new SmtpClient("smtp.gmail.com", 587);

        client.DeliveryMethod        = SmtpDeliveryMethod.Network;
        client.EnableSsl             = true;
        client.UseDefaultCredentials = false;
        client.Credentials           = new System.Net.NetworkCredential("*****@*****.**", "micsnewsletter!");

        try
        {
            client.Send(message);
        }
        catch (Exception ex)
        {
            lbl_output.Text = "Exception caught: " + ex.ToString();
        }
        finally
        {
            lbl_output.Text = "Newsletter is sent sucessfully. Thanks!";
            _subRebind();
        }
    }