Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/258.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 通过网络向文件夹发送邮件_C#_Visual Studio 2008_Sendmail - Fatal编程技术网

C# 通过网络向文件夹发送邮件

C# 通过网络向文件夹发送邮件,c#,visual-studio-2008,sendmail,C#,Visual Studio 2008,Sendmail,我正在尝试发送邮件,在本例中是一个gridview到我机器上的指定文件夹,以便能够查看邮件。因此,我发送邮件,但它不是在文件夹结束。我该怎么做 我将此添加到web.config: <system.net> <mailSettings > <smtp deliveryMethod="Network" from="ArianG@lr.co.za"> <network host="staging.itmaniax.co.za"/> &

我正在尝试发送邮件,在本例中是一个gridview到我机器上的指定文件夹,以便能够查看邮件。因此,我发送邮件,但它不是在文件夹结束。我该怎么做

我将此添加到web.config:

<system.net>
<mailSettings >
  <smtp deliveryMethod="Network" from="ArianG@lr.co.za">
    <network host="staging.itmaniax.co.za"/>
    <specifiedPickupDirectory pickupDirectoryLocation="C:\testdump\emaildump\"/>
  </smtp>
</mailSettings>

这是我发送gridview的代码。(我假设我不需要SmtpClient,因为我不想连接到端口25或587):

private void MailReport()
{
//*****************************************************
字符串to=”arianul@gmail.com";
字符串From=”ArianG@lr.co.za";
字符串subject=“Report”;
string Body=“早上好,请查看附件
请检查d附件

”; Body+=GridViewToHtml(GridView1); Body+=“

问候,
阿里安·格里茨(ITManiax)”; bool send=sendMail(收件人、发件人、主题、正文); if(send==true) { string CloseWindow=“警报('Mail Sent Successfully!”);”; RegisterStartupScript(this.GetType(),“CloseWindow”,CloseWindow,true); } 其他的 { string CloseWindow=“警报('发送邮件时出现问题……请稍后再试!”);”; RegisterStartupScript(this.GetType(),“CloseWindow”,CloseWindow,true); } //***************************************************** } public bool sendMail(字符串收件人、字符串发件人、字符串主题、字符串正文) { boolk=false; 尝试 { MailMessage msg=新的MailMessage(从,到); msg.Subject=主语; 交替视图; SMTP客户端; StringBuilder msgText=新建StringBuilder(); view=AlternateView.CreateAlternateView-FromString(msgText.ToString(),null,“text/html”); msg.AlternateViews.Add(视图); msgText.Append(“



”+正文); //***** /*client=新的SmtpClient(“smtp.gmail.com”,25); client.Host=“staging.itmaniax.co.za”; 客户端端口=25; //**** client.enablesl=true; client.Send(msg)*/ k=真; }
将web.config中的邮件设置更改为:

  <smtp deliveryMethod="SpecifiedPickupDirectory">
    <specifiedPickupDirectory pickupDirectoryLocation="C:\smtp" />

这应该可以做到。或者,在部署解决方案后,您可以通过IIS gui更改设置

亲切的问候

/编辑:当然你需要一个smtp客户端。该程序必须将电子邮件发送到smtp服务器。该邮件只是被IIS接收并填充到一个文件夹中

  <smtp deliveryMethod="SpecifiedPickupDirectory">
    <specifiedPickupDirectory pickupDirectoryLocation="C:\smtp" />