如何用邮件附加文件?配置文件有问题吗? [英] How to attatch file with a mail ? Is there any problem in config file?

查看:72
本文介绍了如何用邮件附加文件?配置文件有问题吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 尝试
           {
               //  FileStream file = null; 

               // //读取文件.这似乎是违规行
               //  file = File.OpenRead(path); 
               //  byte [] Content = new byte [file.Length]; 
               //  file.Read(Content,0,(int)file.Length); 
               //  file.Close(); 
               //  file.Dispose(); 
               //  Label1.Text = Content.ToString(); 

               MailMessage邮件=  MailMessage();
               //  m.ail.To.Add("anzaman_edi@yahoo.com"); 
               mail.To.Add(" );
               mail.To.Add(" );
               //  mail.To.Add("zahir@eminence-bd.org"); 
               mail.From =  MailAddress(" );
               mail.Subject = " ;

               字符串正文= "  +
                             "  +
                             " ;
               mail.Body =身体;
               附件位于= 附件(" );
               mail.Attachments.Add(at);

               mail.IsBodyHtml =  true ;

               SmtpClient smtp =  SmtpClient("  25 );
               smtp.Host = " ; // 或您的SMTP服务器地址
               smtp.Credentials =  System.Net.NetworkCredential
                    (" "  abcdef");
               // 或您的Smtp电子邮件ID和密码
               smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
               smtp.EnableSsl =  true ; ;

               smtp.Send(邮件);
               Label1.Text = " ;
           }
           捕获(例外)
           {
               Label1.Text = ex.Message;
           }



我的Web.Config文件是::

 <?  xml    版本  ="  ? >  <  配置 > 
<   system.net  > 
<   mailSettings  > 
<   smtp     ="   PickupDirectoryFromIis" <  网络    ="   true" 主机   localhost"   端口  ="  25" > 
<  /smtp  > 
<  /mailSettings  > 
<  /system.net  > 
<   system.web  > 
<  编译    ="   true" <  装配体 > 
<  添加   程序集   System.Web.Extensions,Version = 3.5.0.0,Culture =中性,PublicKeyToken = 31BF3856AD364E35" > 
<  添加   程序集   System.Web.Abstractions,版本= 3.5.0.0,文化=中性,PublicKeyToken = 31BF3856AD364E35" > 
<  添加   程序集   System.Core,Version = 3.5.0.0,Culture = neutral, PublicKeyToken = B77A5C561934E089" > 
<  添加   程序集   System.Data.Linq,Version = 3.5.0.0,Culture =中性,PublicKeyToken = B77A5C561934E089"  / > 
<  添加    ="   System.Windows.Forms,Version = 2.0.0.0,Culture =中性,PublicKeyToken = B77A5C561934E089"  / > 
<  添加   程序集   System.Data.Services.Client,版本= 3.5.0.0, Culture = neutral,PublicKeyToken = B77A5C561934E089" > 
<  添加   程序集   System.Data.Services.Design,版本= 3.5.0.0, Culture = neutral,PublicKeyToken = B77A5C561934E089" > 
<  添加   程序集   System.Data.Entity,Version = 3.5.0.0,Culture =中性,PublicKeyToken = B77A5C561934E089"  / > 
<  添加   程序集   System.Design,版本= 2.0.0.0,文化=中性, PublicKeyToken = B03F5F7F11D50A3A" >  /程序集 >  <  /编译 >  <  /system.web  >  <  /配置 >  



比起告诉我我的概率在哪里?
错误消息是:找不到文件"D:\ Text".

解决方案

您必须使用全名,如果您的文件是text.text,请将其写在附件中!


D:\\ Text
这里应该是一个文件.不是文件夹.您所指的是一个文件夹,这可能是您收到错误的原因.指向一个特定的文件,然后查看.

尝试: D:\\ Text \\ MyAttachment.Txt (放置一个名为"MyAttachment"的文本文件,(比如说从记事本中保存))


try
           {
               //FileStream file = null;

               // //Read the file. This appears to be the offending line
               //file = File.OpenRead(path);
               //byte[] Content = new byte[file.Length];
               //file.Read(Content, 0, (int)file.Length);
               //file.Close();
               //file.Dispose();
               //Label1.Text = Content.ToString();

               MailMessage mail = new MailMessage();
               //m.ail.To.Add("anzaman_edi@yahoo.com");
               mail.To.Add("imran3may@gmail.com");
               mail.To.Add("shi01715@yahoo.com");
               //mail.To.Add("zahir@eminence-bd.org");
               mail.From = new MailAddress("shishir64092@gmail.com");
               mail.Subject = "Send Email by asp.net code using google or gmail smtp server";

               string Body = "Hi, I am testing Email function in asp.net" +
                             " using google or gmail smtp server"+
                             " and next time I will send you a document from my .aspx file";
               mail.Body = Body;
               Attachment at = new Attachment("D:\\Text");
               mail.Attachments.Add(at);

               mail.IsBodyHtml = true;

               SmtpClient smtp = new SmtpClient("localhost",25);
               smtp.Host = "smtp.gmail.com"; //Or Your SMTP Server Address
               smtp.Credentials = new System.Net.NetworkCredential
                    ("shishir64092@gmail.com", "abcdef");
               //Or your Smtp Email ID and Password
               smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
               smtp.EnableSsl = true; ;

               smtp.Send(mail);
               Label1.Text = "Mail Send...";
           }
           catch (Exception ex)
           {
               Label1.Text = ex.Message;
           }



My Web.Config file is ::

<?xml version="1.0"?><configuration>
	<system.net>
		<mailSettings>
			<smtp deliveryMethod="PickupDirectoryFromIis">
				<network defaultCredentials="true" host="localhost" port="25"/>
			</smtp>
		</mailSettings>
	</system.net>
	<system.web>
		<compilation debug="true">
			<assemblies>
				<add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
				<add assembly="System.Web.Abstractions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
				<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
				<add assembly="System.Data.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
				<add assembly="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
				<add assembly="System.Data.Services.Client, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
				<add assembly="System.Data.Services.Design, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
				<add assembly="System.Data.Entity, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
				<add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/></assemblies></compilation></system.web></configuration>



Than tell me where is my prob?
The Error Message is: Could not find file ''D:\Text''.

解决方案

You have to point to your File with full name , if your file is text.text , write it in your attachment!


D:\\Text
What is expected here is a FILE. Not a FOLDER. What you are referring to is a folder and that could be the reason why you get an error. Point to a specific file and see.

Try: D:\\Text\\MyAttachment.Txt (Place a text file, (lets say saved from a notepad) named as ''MyAttachment")


这篇关于如何用邮件附加文件?配置文件有问题吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆