Mam formularz zwrotny na mojej witrynie mvc, wyglądaasp.net mvc 4 Wyślij formularz ze strony e-mail
i muszę wysłać moją formę do poczty elektronicznej.
stworzyłem model mojego formularza
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace ComponentTrading.Web.Models
{
public class FeedbackForm
{
public string Name { get; set; }
public string Email { get; set; }
public string Phone { get; set; }
public string Message { get; set; }
}
}
stworzyłem widok na moim formularzu Contacts.cshtml
@using (Html.BeginForm("Contacts", "Home", FormMethod.Post, new { id = "contact-form" }))
{
<fieldset>
@Html.TextBoxFor(model => model.Name, new { @Value = Name })
@Html.TextBoxFor(model => model.Email, new { @Value = "E-mail" })
@Html.TextBoxFor(model => model.Phone, new { @Value = Phone })
@Html.TextAreaFor(model => model.Message, new { @class = "img-shadow" })
<input class="form-button" data-type="reset" value="Clear" />
<input class="form-button" data-type="submit" type="submit" value="Send" />
</fieldset>
}
i napisałem ten kod w moim kontrolera
[HttpGet]
public ActionResult Contacts()
{
FeedbackForm temp = new FeedbackForm();
temp.Message = @Resources.Global.Contacts_Form_Message_Field;
return View(temp);
}
[HttpPost]
public ActionResult Contacts(FeedbackForm Model)
{
string Text = "<html> <head> </head>" +
" <body style= \" font-size:12px; font-family: Arial\">"+
Model.Message+
"</body></html>";
SendEmail("[email protected]", Text);
FeedbackForm tempForm = new FeedbackForm();
return View(tempForm);
}
public static bool SendEmail(string SentTo, string Text)
{
MailMessage msg = new MailMessage();
msg.From = new MailAddress("[email protected]");
msg.To.Add(SentTo);
msg.Subject = "Password";
msg.Body = Text;
msg.Priority = MailPriority.High;
msg.IsBodyHtml = true;
SmtpClient client = new SmtpClient("smtp.mail.ru", 25);
client.UseDefaultCredentials = false;
client.EnableSsl = false;
client.Credentials = new NetworkCredential("TestLogin", "TestPassword");
client.DeliveryMethod = SmtpDeliveryMethod.Network;
//client.EnableSsl = true;
try
{
client.Send(msg);
}
catch (Exception)
{
return false;
}
return true;
}
dont Mam jakieś błędy przy moim kodzie, , ale kiedy wciskam przycisk Wyślij, nie otrzymuję wiadomości e-mail i formularza snt stało się jasne.
użyłem Fiddler Web Debugger i mam do wysyłania kliknij przycisk
Jak widzę, oznacza to, że wszystko w porządku, więc nie mogę undersnand co się dzieje?
Otrzymałem wiadomość e-mail. Powiedz mi, proszę, jak zmieniłeś ustawienia Smtp? – Heidel
@Heidel I usunięto właściwość Credentials i zastąpiłem adres klienta smtp na mój prywatny serwer SMTP. –