Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
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 27-Mar-13 6:29am
Comments
ryanb31 at 27-Mar-13 11:32am
   
What does not working mean? Have you tried "~/Images..." in your Server.MapPath line?
ryanb31 at 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.
ryanb31 at 27-Mar-13 11:33am
   
I looked closer at the code and you aren't even using path anywhere. What is the issue?
vinayak chavan at 27-Mar-13 11:34am
   
pls help to complete ..thx in advance
ThePhantomUpvoter at 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.
vinayak chavan at 27-Mar-13 11:36am
   
dear how to do this??
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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);
  Permalink  
v5
Comments
vinayak chavan at 28-Mar-13 1:56am
   
thx pallavi for reply
 
but it gives error attachment could not found
Pallavi Waikar at 28-Mar-13 2:37am
   
first check ur image is present in image folder..check updated solution
vinayak chavan at 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 at 28-Mar-13 2:44am
   
then try..
MailAttachment attachment = new MailAttachment(path);
msg.Attachments.Add(attachment);
is it ok now
vinayak chavan at 28-Mar-13 3:14am
   
Failed to map the path '/Images/book-cover.jpg'.
Pallavi Waikar at 28-Mar-13 3:19am
   
there problem in path provited check exact path of image folder and use it in Server.MapPath...use string path = Server.MapPath(@"/webSiteFolderName/Images/book-cover.jpg");
vinayak chavan at 28-Mar-13 3:53am
   
not working below ismy code
Pallavi Waikar at 28-Mar-13 4:00am
   
in Server.MapPath also add ur site name as updated solution
for example if websitefolder name is myEmailDemo and in that ur image folder is present then u have to use Server.MapPath(@"/myEmailDemo/Images/book-cover.jpg");
vinayak chavan at 28-Mar-13 4:41am
   
Invalid mail attachment 'H:\DWWebsite\Website\Website\Images\book-cover.jpg'.error is shown
 
i have add-- string path = Server.MapPath(@"Website/Images/book-cover.jpg");
folder name is website, still its not working
Pallavi Waikar at 28-Mar-13 6:40am
   
try for another image..there is no problem in code...check ur image folder present in ur website folder
vinayak chavan at 28-Mar-13 6:58am
   
thx i have check the folder but now its shows invalid mail attchment.
Pallavi Waikar at 28-Mar-13 7:53am
   
check this link for help http://www.codeguru.com/csharp/.net/net_asp/webforms/article.php/c5467/Sending-EMail-with-SystemWebMail.htm...but they are not using server.MapPath...that u have to change
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

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);
  Permalink  

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



Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 27 Mar 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100