在asp.net C中邮件excel附件#

时间:2014-02-19 03:01:43

标签: asp.net file-io mailmessage

我正在尝试用邮件附加一个excel文件,但是没有得到我在做错的地方。没有错误,但邮件无法发送。当我尝试检查文件的服务器路径时,文件是否存在。它显示我是真的,所以我的文件路径是正确的。

邮件正常运行,没有附件。

MailMessage Msg = new MailMessage();
Msg.Subject = "User Creation";
string body = MailSending.PrepareMailBodyWith("WelcomeTemplate.htm", "LoginID", LoginID, "password", password);
            string clientCoverage = System.Web.HttpContext.Current.Server.MapPath("~/file/abc.xlsx");
            bool isFile = false;
            if (File.Exists(clientCoverage))
            {
                isFile = true;
            }
            byte[] bytes = System.IO.File.ReadAllBytes(clientCoverage);
            MemoryStream stream = new MemoryStream(bytes);
            lblerror.Text = avnTutorial + isFile.ToString() ;
            Attachment attachment = new Attachment(stream, "document.xlsx");

            Msg.Attachments.Add(attachment);

            Msg.Body = body;
            Msg.IsBodyHtml = true;
            Msg.From = new MailAddress("info@xyz.in");
            Msg.To.Add(new MailAddress(Email));
            SmtpClient client = new SmtpClient();
            client.Host = "mail.xyz.in";
            client.Port = 25;
            client.Credentials = new System.Net.NetworkCredential("info@xyz.in", "xyz");
            client.Send(Msg);

我试过没有内存流也是代码但不起作用。

附件附件=新附件(clientCoverage,MediaTypeNames.Application.Octet);

0 个答案:

没有答案