Sending mail with attachments programmatically in ASP.NET

后端 未结 4 1891
轮回少年
轮回少年 2021-02-03 13:13

I am dynamically generating a number of different types of files based upon a GridView in ASP.NET - an Excel spreadsheet and a HTML file. I am doing so using this code (this is

4条回答
  •  忘掉有多难
    2021-02-03 13:57

        protected void btnSend_OnClick(object sender, EventArgs e)
        {
            MailMessage mail = new MailMessage();
            byte[] data = new byte[1024];
            MemoryStream stream = new MemoryStream(data);
            Attachment attach = new Attachment(stream, "Attachment file name");
            mail.Attachments.Add(attach);
            new SmtpClient().Send(mail);
        }
    

提交回复
热议问题