Click here to Skip to main content
15,894,405 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi my requirement is to attach a default word file in a mail. that file send to all customer mail-id. here i am using gmail smtp.
here is my sample code
msg.Attachments.Add(data);
MailMessage msg = new MailMessage();
string from = "example@gmail.com";
string ps = "mypassword";
string sub = "checking....";
msg.From = new MailAddress(from, "sender name");//sender
msg.To.Add(new MailAddress(TextBox5.Text));     //receiver

msg.Subject = sub;

msg.IsBodyHtml = true;

Attachment data = new Attachment("Santhosh.doc"); // here is my propblem

msg.Attachments.Add(data);

how can i attached my word document in programatically. here i placed a santhosh.doc that file is shared to all my customer
Posted
Comments
Orcun Iyigun 30-Apr-13 3:04am    
Are you sure the path you provided for that Santhosh.doc is accessible?
srigates 30-Apr-13 3:09am    
that is my doubt . here how can i passed or assigned my file path in default attachment.

1 solution

Read the filpath and filename in any variable and refer following code to attach a file

C#
string attachmentFilename ="C:\\Users\\asdf\\Desktop\\tab_menu\\abc.doc"; //Your file address;
 if (attachmentFilename != null && attachmentFilename!="")
                {
                    message.Attachments.Add(new Attachment(attachmentFilename));
                }
 
Share this answer
 
Comments
srigates 30-Apr-13 3:14am    
if i place my file in same application folder (file\santhosh.doc) how can i search my file path. if this code are upload in to server it cause any problem..
VipulAgrawal 30-Apr-13 3:47am    
Refer following code and modify as per your need

Server.MapPath("~/App_Data/Example.xml");

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