我在线有一个网站,但尚未完成..
我的问题是在底层的“联系我们”论坛。 它没有发送任何邮件..
*在我的本地主机中它正在工作,我不知道什么是不同的
用于发送邮件的java脚本代码:
function sendEmail_click() {
if (Page_ClientValidate()) {
// $("#LoadingImage").show(); //Show loading image
var settings = {
'data': getData(),
'url': "Handlers/SendMail.ashx",
'contentType': 'application/x-www-form-urlencoded; charset=UTF-8'
};
sendEmail(settings);
};
}
function getData() {
var data = {
'firstName': $('#txt_fName').val(),
'lastName': $('#txt_lName').val(),
'phone': $('#txt_phone').val(),
'bName': $('#txt_bName').val(),
'fromMail': $('#txt_email').val(),
'Message': $('#txt_message').val(),
'checkBox': $('#chk_ad').prop('checked')
};
return data;
}
function showOrHideLoadingImage(id, action) {
if (action == "show") {
$("#" + id).show();
} else {
$("#" + id).hide();
}
}
function sendEmail(settings) {
var success = false;
showOrHideLoadingImage("LoadingImage", "show");
$.ajax({
type: "POST",
contentType: settings.contentType,
data: settings.data,
url: settings.url,
dataType: "json",
success: function (data) {
$('#checkMark').css('display', 'inline').fadeOut(20000); //Show check mark image+text
$(".contact_input").each(function () {
$(this).val("");
})
success = true;
},
error: function (data) {
$('#xMark').css('display', 'inline').fadeOut(12000); //Show xMark image+text
success = false;
}
}).always(function () {
showOrHideLoadingImage("LoadingImage", "hide");
});
return success;
}
处理程序:
public void ProcessRequest (HttpContext context) {
//add try catch
// Loads parameters into variables
string firstName = context.Request.Form.Get("firstName");
string lastName = context.Request.Form.Get("lastName");
string phone = context.Request.Form.Get("phone");
string bName = context.Request.Form.Get("bName");
string senderEmail = context.Request.Form.Get("fromMail");
string message = context.Request.Form.Get("message");
string chkBox_ad = context.Request.Form.Get("checkBox");
bool mailSent = Mail.SendEmail(firstName, lastName, bName, phone, senderEmail, message, chkBox_ad);
context.Response.ContentType = "text/plain";
if (mailSent)
{
context.Response.Write("true");
}
else
{
context.Response.Write("false");
}
}
发送邮件功能:
public static bool SendEmail(string firstName, string lastName, string bName, string phone, string senderEmail, string message, string chkBox_ad)
{
chkBox_ad = chkBox_ad == "true" ? "..." : "...";
// Email sending
string eBody = "...";
eBody += "...";
eBody += "...";
eBody += "...";
eBody += "...";
eBody += "...";
MailMessage MyMailMessage = new MailMessage("XXX@gmail.com", "XXX@gmail.com", "smbJob", eBody);
MyMailMessage.IsBodyHtml = true;
try
{
SmtpClient SMTPServer = new SmtpClient();
SMTPServer.Send(MyMailMessage);
return true;
}
catch
{
return false;
}
}
答案 0 :(得分:0)
我不确定这是否是您需要的确切代码,但它应该让您朝着正确的方向前进。确保您也使用正确的using指令。
System.Net.Mail.MailMessage mail =
new System.Net.Mail.MailMessage("xxx@gmail.com", "xxx@gmail.com");
try
{
SmtpClient client = new SmtpClient("smtp.office365.com", 587);
client.Credentials = new System.Net.NetworkCredential()
{
UserName = "someemail@address.com",
Password = "password"
};
client.EnableSsl = true;
}
catch
{
display some error from here
}
答案 1 :(得分:0)
对于任何有此问题的人,我设法解决了这个问题:
1)这是正确的web.config设置(替换" info@yourDomainName.com"使用" goDaddy"电子邮件地址
<system.net>
<mailSettings>
<smtp from="info@yourDomainName.com">
<network host="relay-hosting.secureserver.net" port="25"/>
</smtp>
</mailSettings>
据我所知,&#34; goDaddy&#34;不允许从第三方帐户发送邮件,例如gmail(在与他们进行实时聊天之后),不必写用户名&amp; passowrd,而不是通过SSL。
你的地址应该是你的&#34; goDaddy&#34;电子邮件地址