Click here to Skip to main content
15,892,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have used this code for sending user credential but now i want to send one image with credential


i have add

string path = Server.MapPath(@"Images/book-cover.jpg");

but not working

pls help, thanks in advance...




string sBody = TxtUserName.Text.Trim() + TxtPassword.Text.Trim();
            string path = Server.MapPath(@"Images/book-cover.jpg");

            MailMessage msg = new MailMessage();
            msg.From = "dansingteam@dansingwater.com";
            msg.To = txtEmailID.Text.Trim();
            //MailAddress copy = new MailAddress("vinayak@spareage.com");
            //msg.CC.Add(copy); 
            msg.Subject = "DansingWater Registration Detail";
            msg.Body = ": Welcome to Dansing Water,  Your Credentials are as follows :" + "\r\n" + "User Name :" + TxtUserName.Text.Trim() + "\r\n" + "password : " + TxtPassword.Text.Trim() + "\r\n";
           
            //SmtpClient objClient = new SmtpClient();
            SmtpMail.SmtpServer = "smtp.net4india.com";
            SmtpMail.Send(msg);
Posted
Comments
ZurdoDev 27-Mar-13 11:32am    
What does not working mean? Have you tried "~/Images..." in your Server.MapPath line?
ZurdoDev 27-Mar-13 11:33am    
What does "ya" mean? Also, don't add a comment to your own post here, click the Reply icon so the user you are replying to knows about it.
ZurdoDev 27-Mar-13 11:33am    
I looked closer at the code and you aren't even using path anywhere. What is the issue?
Master Vinu 27-Mar-13 11:34am    
pls help to complete ..thx in advance
[no name] 27-Mar-13 11:35am    
You would either need to send the image as an attachment or change your email to HTML and embed the image.

You can do it by using multi-part messages. Your image should be a separate part encoded as base64. A part should have appropriate content type and content disposition telling the mail viewer program how to treat the picture (suggest downloading it or show embedded in the message content).

You will be able to find it all in the class MailMessage:
http://msdn.microsoft.com/en-us/library/system.net.mail.mailmessage.aspx[^].

Need a code sample? You can easily find some if you do this: http://lmgtfy.com/?q=System.Net.Mail.MailMessage+multipart+with+(image+OR+picture+OR+bitmap)[^].

Good luck,
—SA
 
Share this answer
 
v2
try this code
string path = Server.MapPath(@"/WebSiteFolderName/Images/book-cover.jpg");
MailAttachment attach = new MailAttachment(path);
MailMessage msg = new MailMessage();
msg.Attachments.Add(attach);
 
Share this answer
 
v5
Comments
Master Vinu 28-Mar-13 1:56am    
thx pallavi for reply

but it gives error attachment could not found
Pallavi Waikar 28-Mar-13 2:37am    
first check ur image is present in image folder..check updated solution
Master Vinu 28-Mar-13 2:39am    
ya image in available in folder but iam using

using System.Web.Mail;

is it used for Attachment
Pallavi Waikar 28-Mar-13 2:44am    
then try..
MailAttachment attachment = new MailAttachment(path);
msg.Attachments.Add(attachment);
is it ok now
Master Vinu 28-Mar-13 3:14am    
Failed to map the path '/Images/book-cover.jpg'.
string sBody = TxtUserName.Text.Trim() + TxtPassword.Text.Trim();
string path = Server.MapPath(@"Images/book-cover.jpg"); 
MailMessage msg = new MailMessage();
MailAttachment attachment = new MailAttachment(path);
msg.Attachments.Add(attachment);

msg.From = "dansingteam@dansingwater.com";
msg.To = txtEmailID.Text.Trim();
//msg.Attachment.Add(attach);
 
//MailAddress copy = new MailAddress("vinayak@spareage.com");
//msg.CC.Add(copy); 
msg.Subject = "DansingWater Registration Detail";
msg.Body = ": Welcome to Dansing Water, Your Credentials are as follows :" + "\r\n" + "User Name :" + TxtUserName.Text.Trim() + "\r\n" + "password : " + TxtPassword.Text.Trim() + "\r\n";

//SmtpClient objClient = new SmtpClient();
SmtpMail.SmtpServer = "smtp.net4india.com";
SmtpMail.Send(msg);
 
Share this answer
 

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