Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
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
Comments
ryanb31 at 11-Jan-13 7:59am
   
Your description is not entirely clear; however, where are you stuck?

1 solution

Rate this: bad
good
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",
							true,
							true,
							Type.Missing,
							Type.Missing,
							Type.Missing,
							Type.Missing,
							Type.Missing,
							Type.Missing,
							false,
							Type.Missing,
							Type.Missing,
							Type.Missing,
							Type.Missing,
							Type.Missing);
 

 
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 = "send.from@email.com";
	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.To.Add(range.Text);
	mail.Subject = subject;
	mail.Body = body;
 
	System.Net.Mail.Attachment attachment;
	attachment = new System.Net.Mail.Attachment(attachmentPath);
	mail.Attachments.Add(attachment);
 
	SmtpServer.Port = port;
	SmtpServer.Credentials = new System.Net.NetworkCredential(authUser, authPass);
	SmtpServer.EnableSsl = true;
 

 
	SmtpServer.Send(mail);
}
 

  Permalink  
Comments
Naveen Kumar Kaushik at 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 at 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
0 Sergey Alexandrovich Kryukov 487
1 CPallini 345
2 OriginalGriff 240
3 George Jonsson 159
4 Abdul Samad KP 145
0 OriginalGriff 6,329
1 Sergey Alexandrovich Kryukov 5,700
2 CPallini 4,940
3 George Jonsson 3,469
4 Gihan Liyanage 2,522


Advertise | Privacy | Mobile
Web03 | 2.8.140916.1 | Last Updated 13 Jan 2013
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