Sending Email Using Web Service

Posted by Vijayenderpailla under ASP.NET on 2/18/2012 | Points: 10 | Views : 2188 | Status : [Member] | Replies : 1
Dear Experts,

I have a situation where I need to send the Email to customers using the web service.
I have the details of the customers(i.e. Email ID, Message, Attachmentfilepath etc.) stored in database table,
I could send the mail with attachment, but attachment is not in the format what i sent, it is coming like ATT0007.dat format.
The code is as follows:

BLL objBAL=new BLL();
var list = new List<DTO>();
list = objBAL.getEmailDetails();
foreach (DTO d in list)
LinkedResource receiptpath = new LinkedResource(@"C:\Documents and Settings\vp63\Desktop\new.pdf");//Here i have used a static file path rather than using from DB
AlternateView view = AlternateView.CreateAlternateViewFromString(d.Message, null, "text/plain");
receiptpath.ContentId = "InstitutionLogo";
MailMessage msg = new MailMessage();
msg.Subject = "Mail";
// msg.Attachments.Add(new Attachment(@"C:\Documents and Settings\vp63\Desktop\logo.PNG"));
//string filename = @"C:\Documents and Settings\vp63\Desktop\new.pdf";
//File file = new File(filename);
//string[] mail = d.NotifiedTo.Split(',');
//for (int index = 0; index <= mail.Length; index++)
// msg.To.Add(new MailAddress(mail[index]));
msg.To.Add(new MailAddress(""));
SmtpClient sc = new SmtpClient();

Help is Appreciated.

thanks in advance


Posted by: Rajkatie on: 3/6/2012 [Member] [MVP] Gold | Points: 25

you can try with following code
string fileName = @"C:\Documents and Settings\vp63\Desktop\new.pdf";

Attachment data = new Attachment(filename,getMIMEType(fileName);
ContentDisposition disposition = data.ContentDisposition;
disposition.FileName = Path.GetFileName(files[i]);

private static string GetMimeType(string fileName)
string mimeType = "application/unknown";
string extension = Path.GetExtension(fileName);

if (extension != null)
string ext = extension.ToLower();
RegistryKey regKey = Registry.ClassesRoot.OpenSubKey(ext);
if (regKey != null && regKey.GetValue("Content Type") != null)
mimeType = regKey.GetValue("Content Type").ToString();
catch (Exception ex)
// log exception

return mimeType;

Rajesh Patel
.Net Trainer(MSCD | MCT | MS)
Brainbench (Asp.Net 4.5 and C# 5.0)

Vijayenderpailla, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response