Click here to Skip to main content
15,880,299 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to send a text file as an attachment with email.When i run my code on local development server it runs properly and file gets attached.But when i publish the site on server,It doesnt pick the attachment and the mail is also not sent.Its not an issue of sending mails,bcoz i have checked it by sending mail without attachment,and the mail is sent.The problem is only while attaching file.i have written the path for text file attachment as

string filepath=@"E:\Pwavel\Attachfile\" + filename;
Attachment MyAttachment = new Attachment(filepath);
objmsg.Attachments.Add(MyAttachment);
I have also created "Pwavel" and "Attachfile" folders in E drive of server.
Is there a problem in path ? or any permission issue? i am not able to understand what the problem is..Please Help me...
Posted
Updated 28-Jul-14 23:48pm
v2
Comments
Agent__007 29-Jul-14 6:08am    
Do you have some sort of logging mechanism in place?
pwavell 29-Jul-14 6:12am    
logging mechanism ? like?.I have a login form..are u asking about that?
vangapally Naveen Kumar 29-Jul-14 7:00am    
i think the server is blocking smtp...
what error you are getting ccheck error log.....
pwavell 29-Jul-14 7:12am    
but if i send mail without attachment everything works fine.the mail is sent.
vangapally Naveen Kumar 29-Jul-14 7:16am    
what error you are getting?

Hello pwavell

use This Code

System.Net.Mail.Attachment mailatt = new Attachment(File);
            mail.Attachments.Add(mailatt);


Because
System.Web.Mail and System.Web.Mail Conflict Each Other


Happy Coding
 
Share this answer
 
hello pwavell

first you saved the file into Webapplication through following Code

fileupload.SaveAs(FilePath+fileName)


Then Attachment the file
 
Share this answer
 
Comments
pwavell 29-Jul-14 6:23am    
the file is already present at the given path .I dont need to upload file.

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