0

メッセージを表示できるように、メール(この場合はグリッドビュー)をマシン上の指定されたフォルダーに送信しようとしています。このようにメールを送信していますが、フォルダに保存されていません。これどうやってするの?

これを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>

これは、グリッドビューを送信するための私のコードです。(25または587のポートに接続したくないので、SmtpClientは必要ないと思います):

private void MailReport()
{
    //*****************************************************
    string to = "arianul@gmail.com";
    string From = "ArianG@lr.co.za";
    string subject = "Report";
    string Body = "Good morning, Please view attachment<br> Plz Check d Attachment <br><br>";

    Body += GridViewToHtml(GridView1);

    Body += "<br><br>Regards,<br>Arian Geryts(ITManiax)";
    bool send = sendMail(to, From, subject, Body);

    if (send == true)
    {
        string CloseWindow = "alert('Mail Sent Successfully!');";
        ClientScript.RegisterStartupScript(this.GetType(), "CloseWindow", CloseWindow, true);
    }
    else
    {
        string CloseWindow = "alert('Problem in Sending mail...try later!');";
        ClientScript.RegisterStartupScript(this.GetType(), "CloseWindow", CloseWindow, true);
     }
    //*****************************************************

}

public bool sendMail(string to, string from, string subject, string body)
{
    bool k = false;
    try
    {
        MailMessage msg = new MailMessage(from, to);
        msg.Subject = subject;

        AlternateView view;
        SmtpClient client;
        StringBuilder msgText = new StringBuilder();
        view = AlternateView.CreateAlternateViewFromString(msgText.ToString(), null, "text/html");
        msg.AlternateViews.Add(view);
        msgText.Append(" <html><body><br></body></html> <br><br><br>  " + body);

        //*****
        /*client = new SmtpClient("smtp.gmail.com", 25);
        client.Host = "staging.itmaniax.co.za";
        client.Port = 25;

        //****
        client.EnableSsl = true;
        client.Send(msg);*/

        k = true;     
    }
4

1 に答える 1

1

web.configのメール設定を次のように変更します。

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

これでうまくいくはずです。または、ソリューションを展開した後、IISGUIを介して設定を変更することもできます。

敬具。

/ edit:もちろん、SMTPクライアントが必要です。プログラムは、SMTPサーバーに電子メールメッセージを送信する必要があります。メッセージはIISによって取得され、フォルダーに詰め込まれます。

于 2013-01-16T10:16:54.973 に答える