ASP.NET郵件提醒功能按每月的哪天進行發送

來源:互聯網
上載者:User

前臺全部代碼:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="MailPJQGD.aspx.cs" Inherits="MailPJQGD" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>無標題頁</title>
    <style type="text/css">
        .style1
        {
            width: 100%;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <asp:Timer ID="Timer1" runat="server" ontick="Timer1_Tick">
            </asp:Timer>
            <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
        </ContentTemplate>
        </asp:UpdatePanel>
    </div>
    </form>
</body>
</html>

 

後臺代碼:

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Net.Mail;

public partial class MailPJQGD : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
       
    }
    //public void SendMail(string strSmtpServer, string UserName, string Password, string strFrom, string strto, string strSubject, string strBody)

    public void SendSMTPEMail(string strSmtpServer, string strFrom, string strFromPass, string strto, string strSubject, string strBody)
    {
        //產生一個使用Smtp發送郵件的客戶端對象;
        System.Net.Mail.SmtpClient Client = new SmtpClient(strSmtpServer);
        Client.Port = 25;
        Client.UseDefaultCredentials = false;//表示以當前登入使用者的預設憑據進行身分識別驗證 
        //Client.Credentials = new System.Net.NetworkCredential(UserName, Password);
        Client.Credentials = new System.Net.NetworkCredential(strFrom, strFromPass);   //包含用戶名和密碼;
        Client.DeliveryMethod = SmtpDeliveryMethod.Network;
        System.Net.Mail.MailMessage message = new MailMessage(strFrom, strto, strSubject, strBody);
        message.BodyEncoding = System.Text.Encoding.UTF8;
        message.IsBodyHtml = true;
        Client.Send(message);  //發送
    }
    public static int iii = 0;
    protected void Timer1_Tick(object sender, EventArgs e)
    {
        if (iii == 0)
        {
            string day = DateTime.Now.Day.ToString();
            if (day == "15")
            {
                string server = "192.168.2.8";//定義伺服器位址
                string sendEmail = "mis10@tjpcb.com";//定義寄件者郵箱
                string sendEmailPassWord = "123456";//定義寄件者郵箱密碼
                string getEmail = "lishuanzhu@tjpcb.com";//擷取收件者的郵箱地址
                string titleEmail = "配件請購單需務數量明細導出";//定義郵件的主題
                string context = "";//定義郵件的內容
                string str = "server=192.168.3.127;database=FlowMaster;UId=sa;password=bruce_zhao888418";
                SqlConnection sqlcon = new SqlConnection(str);
                sqlcon.Open();
                string sqlstr = @"
select  distinct  * from (
select  nows,ApplyerDeptName,pinming1,norm1,Material1,quantity1
from WLQGD_View 
where applydatetime>='2010-8-15' and applydatetime<='2010-9-14' and  Status = '100'  and
(quantity1<>'0' and quantity1 is not null and quantity1<>'' and pinming1<>'' and pinming1 is not null)
union all
select  nows,ApplyerDeptName,pinming2,norm2,Material2,quantity2 
from WLQGD_View 
where applydatetime>='2010-8-15' and applydatetime<='2010-9-14' and  Status = '100' and
(quantity2<>'0' and quantity2 is not null and quantity2<>'' and pinming2<>'' and pinming2 is not null)
union all
select  nows,ApplyerDeptName,pinming3,norm3,Material3,quantity3 
from WLQGD_View 
where applydatetime>='2010-8-15' and applydatetime<='2010-9-14' and Status = '100' and
(quantity3<>'0' and quantity3 is not null and quantity3<>'' and pinming3<>'' and pinming3 is not null)
union all
select  nows,ApplyerDeptName,pinming4,norm4,Material4,quantity4 
from WLQGD_View
where applydatetime>='2010-8-15' and applydatetime<='2010-9-14' and  Status = '100' and
(quantity4<>'0' and quantity4 is not null and quantity4<>'' and pinming4<>'' and pinming4 is not null)
union all
select  nows,ApplyerDeptName,pinming5,norm5,Material5,quantity5 
from WLQGD_View 
where applydatetime>='2010-8-15' and applydatetime<='2010-9-14' and  Status = '100' and
(quantity5<>'0' and quantity5 is not null and quantity5<>'' and pinming5<>'' and pinming5 is not null)
union all
select  nows,ApplyerDeptName,pinming6,norm6,Material6,quantity6 
from WLQGD_View 
where applydatetime>='2010-8-15' and applydatetime<='2010-9-14' and  Status = '100' and
(quantity6<>'0' and quantity6 is not null and quantity6<>'' and pinming6<>'' and pinming6 is not null)
union all
select  nows,ApplyerDeptName,pinming7,norm7,Material7,quantity7 
from WLQGD_View 
where applydatetime>='2010-8-15' and applydatetime<='2010-9-14' and  Status = '100' and
(quantity7<>'0' and quantity7 is not null and quantity7<>'' and pinming7<>'' and pinming7 is not null)
union all
select  nows,ApplyerDeptName,pinming8,norm8,Material8,quantity8 
from WLQGD_View 
where applydatetime>='2010-8-15' and applydatetime<='2010-9-14' and  Status = '100' and
(quantity8<>'0' and quantity8 is not null and quantity8<>'' and pinming8<>'' and pinming8 is not null)
)A order by nows asc

";
                SqlDataAdapter sqlda = new SqlDataAdapter(sqlstr, sqlcon);
                DataSet ds = new DataSet();
                string tableStr = @"<table border='0' cellpadding='0'  cellspacing='0' style='font-family:宋體; font-size:14px; color:Blue;'>
           <tr><td>您好:</td></tr>
           <tr><td>&nbsp;&nbsp;&nbsp;如下為2010-8-15至2010-9-14日,請購單需備數量明細,請收悉!</td></tr>
        </table><br/><p></p><table border='0' cellpadding='0'  cellspacing='0' style='font-family:宋體; font-size:14px; color:Blue;' align='left'>
         <tr><td>軟硬體維護組<br /> 敬呈 </td></tr>
       </table><br/><p></p><br/><p></p><table border='1' cellpadding='0' cellspacing='0' align='left'>
                    <tr style='color: #FFFFFF;background-color: #FF9900;' align='center'><td>填單時間</td><td>申請課別</td><td>品名</td><td>規格</td><td>品牌材質</td><td>需備數量</td></tr>";
                sqlda.Fill(ds);
                if (ds.Tables[0].Rows.Count > 0)
                {
                    for (int i = ds.Tables[0].Rows.Count; i > 0; i--)
                    {
                        string nows = ds.Tables[0].Rows[i - 1][0].ToString();
                        string ApplyDepName=ds.Tables[0].Rows[i - 1][1].ToString();
                        string pingming1 = ds.Tables[0].Rows[i - 1][2].ToString();
                        string norm1 = ds.Tables[0].Rows[i - 1][3].ToString();
                        string Material1= ds.Tables[0].Rows[i - 1][4].ToString();
                        string quantity1 = ds.Tables[0].Rows[i-1][5].ToString();
                        tableStr += @"
<tr align='center'><td style='font-size:12px;width:200px;'>" + nows + @"</td><td style='font-size:12px;width:200px;'>" + ApplyDepName + @"</td><td style='font-size:12px;width:200px;'>" + pingming1 + @"</td><td style='font-size:12px;width:200px;'>" + norm1 + @"&nbsp;</td><td style='font-size:12px;width:200px;'>" + Material1 + @"&nbsp;</td><td style='font-size:12px;width:200px;'>" + quantity1 + @"</td></tr>
";
                    }
                    tableStr += @"</table>";
                    SendSMTPEMail(server, sendEmail, sendEmailPassWord, getEmail, "配件請購單需務數量明細導出", tableStr);
                    SendSMTPEMail(server, sendEmail, sendEmailPassWord, "mis12@tjpcb.com", titleEmail, tableStr);
                    SendSMTPEMail(server, sendEmail, sendEmailPassWord, "qianshengjun@tjpcb.com", titleEmail, tableStr);
                }
            }
            iii++;
            Label1.Text = "success";
        }
    }

}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.