如何使用附件文件发送邮件

时间:2016-06-04 12:26:40

标签: asp.net sendmail

我正在尝试使用attache发送邮件(.docx或.pdf)并且我成功完成了此操作。但是,当我尝试从接收方邮件ID下载附加文件时,.docx文件作为空白文档打开,.pdf文件已损坏。我无法理解这里发生了什么。 我的代码如下。

MailMessage mail = new MailMessage();
                SmtpClient SmtpServer = new SmtpClient("mail.360google.in");

                mail.From = new MailAddress("sender@360google.in");
                mail.To.Add("receiver@gmail.com");
                mail.Subject = "Test Mail";
                mail.Body = "This is for testing SMTP mail from GMAIL";

                string FileName = Path.GetFileName(FUResume.PostedFile.FileName);
                mail.Attachments.Add(new Attachment(FUResume.PostedFile.InputStream, FileName));

                SmtpServer.Port = 587;
                SmtpServer.Credentials = new System.Net.NetworkCredential("sender@360google.in", "mypassword");
                SmtpServer.EnableSsl = true;
                ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)  { return true; };

                SmtpServer.Send(mail);

请任何人告诉我这里发生的问题之王是什么,并给我正确的代码。

0 个答案:

没有答案
相关问题