Click here to Skip to main content
13,052,558 members (55,299 online)
Rate this:
Please Sign up or sign in to vote.
See more:
What I Want to do? I want to send email to the person who's mail id enter in a excel sheet. when u send the email to all the mail id no body can check another person mail id. I just want to used the BCC Concept in my mail Demo with attachment of multiply file.another thing i want to do is this the name of the person who is mention in front of mail id in excel file that is also mention in the mail.........
Posted 11-Jan-13 0:07am
ryanb31 11-Jan-13 7:59am
Your description is not entirely clear; however, where are you stuck?

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

I have not tested this snippet to make sure it works...mainly because i think working off of an excel worksheet as database is pointless.

But anyways according to your description (not entirely clear) i think this is what you were looking for, again not tested so may have issues. You will need to add the com reference for Excel.

using Excel = Microsoft.Office.Interop.Excel;
using System.Net.Mail;
Excel.Application excel = null;
Excel.Workbook wkbk = null;
excel = new Excel.Application();
wkbk = excel.Workbooks.Open(@"c:\path\to\excel\file.xls",

Excel.Worksheet sheet = wkbk.Sheets["Sheet1"] as Excel.Worksheet;
Excel.Range getRange = null;

if (sheet != null)
	getRange = sheet.get_Range("A1", Type.Missing);
foreach (Excel.Range range in getRange)
	string server = "YourSmtpServerHer";
	int port = 25;
	string authUser = "YourSmtpUsername";
	string authPass = "YourSmtpPass";
	string sendFrom = "";
	string subject = "Subject Of Your Mail";
	string body = "put the body of your mail here";
	string attachmentPath = @"c:\path\to\your\file\here.txt";
	MailMessage mail = new MailMessage();
	SmtpClient SmtpServer = new SmtpClient(server, port);
	mail.From = new System.Net.Mail.MailAddress(sendFrom);
	mail.Subject = subject;
	mail.Body = body;
	System.Net.Mail.Attachment attachment;
	attachment = new System.Net.Mail.Attachment(attachmentPath);
	SmtpServer.Port = port;
	SmtpServer.Credentials = new System.Net.NetworkCredential(authUser, authPass);
	SmtpServer.EnableSsl = true;

Naveen Kumar Kaushik 13-Jan-13 6:21am
Thanks for the code but i had already tried this one but i didn't get my desire output what i wanted. but any way thanks for your code & support for me......
Plyswthsqurles 13-Jan-13 11:26am
Can you not dump the excel spreadsheet into some form of database? anything? sql server, mysql something?

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 13 Jan 2013
Copyright © CodeProject, 1999-2017
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