我想使用控制台应用程序发送邮件excel

问题描述:

我的代码如下



SqlConnection sqlConnection = new SqlConnection(connectionstring);

SqlCommand cmd = new SqlCommand();

SqlDataReader阅读器;

DataSet ds = new DataSet();

cmd.CommandText =select * from Empdetails;

cmd.CommandType = CommandType.Text;

cmd.Connection = sqlConnection;

sqlConnection.Open();

reader = cmd。 ExecuteReader();

if(reader.HasRows)

{

using(System.IO.StreamWriter fileOutput =

new System.IO.StreamWriter(@C:\ Users \God \Desktop\DataDump \Excel.xls))

{

while(reader.Read())

{



for(int i = 0; i< reader.Fi eldCount; i ++)

{

fileOutput.AutoFlush = true;

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

}

fileOutput.Write(\ n);

}

}

sqlConnection.Close();

}



当我执行上面的代码时选择*来自Empdetails输出保存在以下文件夹中



C:\ Users \ God \Desktop\DataDump \ Excel.xls





i想发送上述excel文件发送邮件。



我该怎么办asp.net使用c#



我尝试过:



如何从文件夹发送邮件excel数据。

My code as follows

SqlConnection sqlConnection = new SqlConnection(connectionstring);
SqlCommand cmd = new SqlCommand();
SqlDataReader reader;
DataSet ds = new DataSet();
cmd.CommandText = "select * from Empdetails";
cmd.CommandType = CommandType.Text;
cmd.Connection = sqlConnection;
sqlConnection.Open();
reader = cmd.ExecuteReader();
if (reader.HasRows)
{
using (System.IO.StreamWriter fileOutput =
new System.IO.StreamWriter(@"C:\Users\God\Desktop\DataDump\Excel.xls"))
{
while (reader.Read())
{

for (int i = 0; i < reader.FieldCount; i++)
{
fileOutput.AutoFlush = true;
fileOutput.Write(reader[i].ToString() +"\t");
}
fileOutput.Write("\n");
}
}
sqlConnection.Close();
}

when i execute the above code select * from Empdetails ouput is saved in the below folder

C:\Users\God\Desktop\DataDump\Excel.xls


i want to send the above excel file to send mail.

for that how can i do in asp.net using c#

What I have tried:

how to send mail the excel data from the folder.

如何发送带附件的电子邮件? [ ^ ]



谷歌c#发送带附件的电子邮件了解更多示例。您需要一个smtp服务器来发送电子邮件,使用sys admin提供的服务器(如果在公司内部网中)或者您的webhost或ISP提供的服务器。
How do I send an email with attachments?[^]

google "c# send email with attachments" for more examples. You'll need an smtp server to send the email through, use one provided by your sys admin if in a company intranet, or the one provided by your webhost or ISP.