1

基本的なメールをフォルダーに送信しようとしていますが、メールを受信して​​も本文が完全に欠落しています。

private void MailReport()
{

    string to = "arianul@gmail.com";
    string From = "ArianG@lr.co.za";
    string subject = "Report";
    **string Body = "Dear sir ,<br> Plz Check d Attachment <br><br>";**


    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("<body><br></body></html> <br><br><br>  " + body);

        client = new SmtpClient();
        client.Host = "staging.itmaniax.co.za";
        client.Send(msg);

        k = true;

    }
    catch (Exception exe)
    {
        Console.WriteLine(exe.ToString());
    }
    return k;


}

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

Visual Studio-2008で行われているように、問題は本体とhtmlにあると感じています。おそらくアドバイスはありますか?

4

2 に答える 2

1

あなたが欠けているようです:

MailMessage msg = new MailMessage(from, to);
msg.Subject = subject;

msg.Body = body; <--- try adding this and see what happens.

あなたの例では msg.Body プロパティが空です。それが本文テキストを送信しない理由だと思います。

于 2013-01-16T12:03:45.983 に答える
1

以下のようなものを試すことができます。

protected void SendMail()
{
    // Gmail Address from where you send the mail
    var fromAddress = "Gmail@gmail.com";
    // any address where the email will be sending
    var toAddress = YourEmail.Text.ToString(); 
    //Password of your gmail address
    const string fromPassword = "Password";
     // Passing the values and make a email formate to display
    string subject = YourSubject.Text.ToString();
    string body = "From: " + YourName.Text + "\n";
    body += "Email: " + YourEmail.Text + "\n";
    body += "Subject: " + YourSubject.Text + "\n";
    body += "Question: \n" + Comments.Text + "\n";
    // smtp settings
    var smtp = new System.Net.Mail.SmtpClient();
    {
        smtp.Host = "smtp.gmail.com";
        smtp.Port = 587;
        smtp.EnableSsl = true;
        smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
        smtp.Credentials = new NetworkCredential(fromAddress, fromPassword);
        smtp.Timeout = 20000;
    }
    // Passing values to smtp object
    smtp.Send(fromAddress, toAddress, subject, body);
}

protected void Button1_Click(object sender, EventArgs e)
{
    try
    {
        //here on button click what will done 
        SendMail();
        DisplayMessage.Text = "Your Comments after sending the mail";
        DisplayMessage.Visible = true;
        YourSubject.Text = "";
        YourEmail.Text = "";
        YourName.Text = "";
        Comments.Text = "";
    }
    catch (Exception) { }
}

詳細については、Send Mail / Contact Form using ASP.NET and C# を確認してください。

これがお役に立てば幸いです。

于 2013-01-16T12:07:06.507 に答える