Click here to Skip to main content
15,905,679 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
C#
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
<?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'.
Posted
Updated 5-Jun-12 2:31am
v2
Comments
OriginalGriff 5-Jun-12 8:29am    
What happens when you run it?
Anything? Nothing? Is there an error message? Or what?
UL UL ALBAB 5-Jun-12 8:30am    
The Error Message is:
Could not find file 'D:\Text'.
kodeLogic 5-Jun-12 8:31am    
Attachment at = new Attachment("D:\\Text");
My be the problem is that, there is no extension with the file you are attaching.
e.g text.txt
UL UL ALBAB 5-Jun-12 8:33am    
Than I got: Could not find file 'D:\Text.txt'.
UL UL ALBAB 5-Jun-12 8:33am    
Than I got:
Could not find file 'D:\Text.txt'.

You have to point to your File with full name , if your file is text.text , write it in your attachment!
 
Share this answer
 
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")
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900