本文介绍了System.Net.Mail没有发送我想要的信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿fellas!



我有一个联系表格的以下代码发送到我的电子邮件地址



Hey fellas!

I have the following code for a contact form that is sent to my email address

[HttpPost]
        public ActionResult Contact(ContactsModel model)
        {
            if (ModelState.IsValid)
            {
                InsertContact(model.Name, model.Phone, model.Email, model.Comments);

                MailMessage message = new MailMessage();
                message.From = new MailAddress("sender1@foo.bar.com");
                message.To.Add(new MailAddress("lotusms@outlook.com"));
                message.Subject = "This is my subject";
                message.Body = "This is the content";
                SmtpClient client = new SmtpClient();
                client.Send(message);

                TempData["notice"] = "Someone will reply as soon as possible.";
                return RedirectToAction("Index", "Home");
            }

            return View();

        }





好​​消息是它有效。坏消息是:



1.它进入垃圾文件夹。有没有办法解决这个问题?

2.它发送一封来自sender1@foo.bar.com的电子邮件给我发送这是我的内容而不是textarea中的实际内容。



我怎样才能使消息。从实际上发送在电子邮件文本框中输入的电子邮件地址,以及message.Body发送TextArea的内容。



这是我的表格。





The good news is that it works. The bad news are:

1. It goes to the junk folder. Is there a way to get around this?
2. It sends an email from sender1@foo.bar.com to me with a "This is my content" instead of the actual content in the textarea.

How can I make it so that the message.From actually sends the email address entered in the email textbox, and the message.Body to send the content of the TextArea.

Here is my form as well.

<div id="contact-form">
            @using(Html.BeginForm())
            {
                @Html.LabelFor(model => model.Name)
                @Html.TextBoxFor(model => model.Name)<br class="clear" />
                @Html.ValidationMessageFor(model => model.Name)<br class="clear" /> <br />

                @Html.LabelFor(model => model.Phone)
                @Html.TextBoxFor(model => model.Phone)<br class="clear" />
                @Html.ValidationMessageFor(model => model.Phone)<br class="clear" /> <br />

                @Html.LabelFor(model => model.Email)
                @Html.TextBoxFor(model => model.Email)<br class="clear" />
                @Html.ValidationMessageFor(model => model.Email)<br class="clear" /> <br />

                @Html.LabelFor(model => model.Comments)
                @Html.TextAreaFor(model => model.Comments, 10, 40, null)<br class="clear" />
                @Html.ValidationMessageFor(model => model.Comments)<br class="clear" /> <br />


                <button type="submit">SEND</button>
                <button type="reset">CLEAR</button>
            }
        </div>

谢谢

推荐答案

message.To.Add(new MailAddress(model.Email));



/ ravi


/ravi



[HttpPost]
public ActionResult Contact(ContactsModel model)
{
    if (ModelState.IsValid)
    {
        InsertContact(model.Name, model.Phone, model.Email, model.Comments);

        MailMessage message = new MailMessage();
        message.From = new MailAddress(model.Email);
        message.To.Add(new MailAddress("lotusms@outlook.com"));
        message.Subject = "This is my subject";
        message.Body = model.Comments;
        SmtpClient client = new SmtpClient();
        client.Send(message);

        TempData["notice"] = "Someone will reply as soon as possible.";
        return RedirectToAction("Index", "Home");
    }
    return View();
}



问候,


Regards,


这篇关于System.Net.Mail没有发送我想要的信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 17:44
查看更多