我的邮件使用google stmp在asp.net中发送代码MVC在本地服务器上工作正常,但在远程服务器sage.arvixe.com上提供内部服务器错误500
这是我的控制器代码:
string email = "**@**.com";
string password = "***";
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("my.smtp.server.com");
mail.From = new MailAddress(email, "Company");
mail.To.Add("something@gmail.com");
mail.Subject = "Feedback";
string body = "CompanyName " + data.CompanyName + "<br/> Contact Person Name " + data.ContactPersonName + "<br/> Designation " + data.Designation + "<br/> EmailID " + data.EmailID + "<br/> MobileCellNo " + data.MobileCellNo + "<br/> OfficePhoneNo " + data.OfficePhoneNo + "<br/> FaxNo " + data.FaxNo + "<br/> Address " + data.Address + "<br/> CityState " + data.CityState + "<br/> PostalCode " + data.PostalCode + "<br/> Country " + data.Country + "<br/> Description " + data.Description + "";
mail.Body = body;
mail.IsBodyHtml = true;
//SmtpServer.UseDefaultCredentials = false;
SmtpServer.Port =25;
SmtpServer.Credentials = new System.Net.NetworkCredential(email, password);
//SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);
答案 0 :(得分:0)
我不确定,但似乎您必须启用SSL以正确使用此Google服务。
也许你会在
中找到更多帮助本教程:http://www.dustinhorne.com/post/Sending-Email-With-Google-Mail-and-ASPNET
或此主题:https://productforums.google.com/forum/#!topic/apps/fg5RNrQhdFY
答案 1 :(得分:0)
嗨试试这段代码它正在运作
[HttpPost]
public ActionResult Form(string receiverEmail, string subject,string message)
{
try
{
if (ModelState.IsValid) {
var senderemail = new MailAddress("xxxxx@gmail.com", "Demo Mail");
var receiveremail = new MailAddress(receiverEmail, "Receiver");
var password = "xxxxx";
var sub = subject;
var body = message;
var smtp = new SmtpClient {
Host = "smtp.gmail.com",
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(senderemail.Address, password)
};
using (var mess = new MailMessage(senderemail, receiveremail)
{
Subject = subject,
Body = body
})
{
smtp.Send(mess);
}
return View();
}
}
catch(Exception){
ViewBag.Error = "There is some thing went Wrong";
}
return View();
}
}