从Excel表格中选择Asp .Net电子邮件ID中的电子邮件 [英] Send Email In Asp .Net Email Id Pick From Excel Sheet

查看:80
本文介绍了从Excel表格中选择Asp .Net电子邮件ID中的电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做什么?我想发送电子邮件给邮件ID在excel表中输入的人。当你把电子邮件发送到所有的邮件ID时,没有人可以检查另一个人的邮件ID。我只想在我的邮件演示中使用BCC概念附加多重文件。我想要做的另一件事就是在邮件中也提到的excel文件中邮件ID前面提到的人的名字。 ........

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.........

推荐答案

我没有测试这个片段以确保它有效...主要是因为我认为使用excel工作表作为数据库是没有意义的。



但是根据你的描述(不完全清楚)我认为这是你正在寻找的,再次未经测试可能有问题。您需要为Excel添加com参考。



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


这篇关于从Excel表格中选择Asp .Net电子邮件ID中的电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆