尝试向文件夹发送基本电子邮件 [英] trying to send a basic email to folder

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

问题描述

我正在尝试向文件夹发送基本电子邮件,但是,尽管我确实收到了电子邮件,但尸体完全丢失了.

I am trying to send a basic email to a folderbut howerver, even though I do receive the email, the body is missing completely.

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上. 可能有什么建议吗?

I have the feeling the problem lies with the body and the html as it is done with visual studio-2008. Any advice perhaps?

推荐答案

您可以尝试以下操作.

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) { }
}

有关更多信息,请检查 使用ASP.NET和C#发送邮件/联系表

For more information check Send Mail / Contact Form using ASP.NET and C#

我希望这会对您有所帮助.

I hope this will help to you.

这篇关于尝试向文件夹发送基本电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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