将excel文件发送给每个人的电子邮件 [英] Send excel file to email for each person

查看:175
本文介绍了将excel文件发送给每个人的电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码如下



public void Getfunction(int j)

{

string connectionstring = Server =(local); initial catalog = Test; Trusted_Connection = True;

SqlConnection sqlConnection = new SqlConnection(connectionstring);

SqlCommand cmd = new SqlCommand();

SqlDataReader阅读器;

DataSet ds = new DataSet();

cmd.CommandText =select * from Empdetails;

cmd.CommandText + =where shifttype = @par;

cmd.Parameters.Add(@ par,SqlDbType.Int).Value = j;

cmd.CommandType = CommandType.Text;

cmd.Connection = sqlConnection;

sqlConnection.Open();

reader = cmd .ExecuteReader();



if(reader.HasRows)

{

System.IO.StreamWriter sw_In = new System.IO.StreamWriter(@C:\ Users\God \Desktop\DataDump \+ j +Excel.xls);

while(reader.Read())

{

for(int i = 0;我< reader.FieldCount; i ++)

{

sw_In.AutoFlush = true;

sw_In.Write(reader [i] .ToString()+\ t );

}

sw_In.Write(\ n);

}



}

sqlConnection.Close();

reader.Close();

}







static void Main(string [] args)

{



程序ps =新程序();

int [] numbers = {1,2};

foreach(int j in数字)

{

ps.Getfunction(j);

System.Console.Write({0},j); < br $>
}

}



当我在datadump文件夹2下运行上面的代码时,已经下载了excel < b r />
,名称为1Excel,2Excel。



i想发送以上两个excel邮件



1EXcel发送邮件至rajesh@gmail.con

2Excel发送邮件至Vikash@gmail.com



为什么我如何将上述2个excel发送给两个不同的人发送邮件c#



我尝试过:



发送邮件excel给两个不同的人发送邮件c#

My code as follows

public void Getfunction(int j)
{
string connectionstring = "Server=(local);initial catalog=Test;Trusted_Connection=True";
SqlConnection sqlConnection = new SqlConnection(connectionstring);
SqlCommand cmd = new SqlCommand();
SqlDataReader reader;
DataSet ds = new DataSet();
cmd.CommandText = "select * from Empdetails";
cmd.CommandText += " where shifttype = @par ";
cmd.Parameters.Add("@par", SqlDbType.Int).Value = j;
cmd.CommandType = CommandType.Text;
cmd.Connection = sqlConnection;
sqlConnection.Open();
reader = cmd.ExecuteReader();

if (reader.HasRows)
{
System.IO.StreamWriter sw_In = new System.IO.StreamWriter(@"C:\Users\God\Desktop\DataDump\" + j + "Excel.xls");
while (reader.Read())
{
for (int i = 0; i < reader.FieldCount; i++)
{
sw_In.AutoFlush = true;
sw_In.Write(reader[i].ToString() + "\t");
}
sw_In.Write("\n");
}

}
sqlConnection.Close();
reader.Close();
}



static void Main(string[] args)
{

Program ps = new Program();
int[] numbers = { 1, 2 };
foreach (int j in numbers)
{
ps.Getfunction(j);
System.Console.Write("{0} ", j);
}
}

When i run the above code in Desktop under datadump folder 2 excel has been downloaded
in the name of 1Excel, 2Excel.

i want to send the above two excel to mail

1EXcel to send mail to rajesh@gmail.con
2Excel to send mail to Vikash@gmail.com

for that how can i send the above 2 excel to two different persons send mail in c#

What I have tried:

Send mail excel to to two different persons send mail in c#

推荐答案

参见SmtpClient类(System.Net.Mail) [ ^ ],谷歌会找到很多样品。
See SmtpClient Class (System.Net.Mail)[^], and Google will find you many samples.


这篇关于将excel文件发送给每个人的电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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