我的表单有问题,我无法发送。如果我输入错误的详细信息(安全代码,电子邮件,空字段等),我会在屏幕上显示错误,这是正确的。
但是当我输入所有正确的数据时,我无法发送表单,我收到此错误:
提交表单时出错。请检查以下内容:
但是列表是空的。
SmtpClient smtpClient = new SmtpClient();
MailMessage message = new MailMessage();
try
{
MailAddress fromAddress = new MailAddress("noreply@domain.com", "string1");
// decide who message goes to
string emailGoesTo = "person1@domain.com";
MailAddress toAddress = new MailAddress(emailGoesTo.ToString(), "string1");
message.From = fromAddress;
message.To.Add(toAddress);
message.To.Add("person2@domain.com");
message.Subject = "string2";
message.Body = "New Website Contact Request";
message.Body += "------------------------------------------\r\n";
message.Body += "Name: " + your_name.Text + "\r\n";
message.Body += "Email: " + your_email.Text + "\r\n";
message.Body += "Telephone: " + your_telephone.Text + "\r\n";
message.Body += "Company: " + your_company.Text + "\r\n";
message.Body += "Address: " + your_address.Text + "\r\n";
message.Body += "Postcode: " + your_zip.Text + "\r\n";
message.Body += "Enquiry: " + your_enquiry.Text + "\r\n";
// smtpClient.Host = "string3";
smtpClient.Host = "string4";
smtpClient.Credentials = new System.Net.NetworkCredential("string5", "string6");
smtpClient.Send(message);
Response.Redirect("thankyou.aspx");
}
catch (Exception ex)
{
statusLabel.Text = "Coudn't send the message!";
}
我是noobie,所以有任何1 string5
& string6
拜托?
还有什么问题?如何使这个表格有效?
答案 0 :(得分:2)
从未尝试使用smtpclient.host,但以下工作原理。只需要添加邮件服务器的ip /主机名,并确保它被设置为允许从调用代码的机器中继。并用您想要的文本替换字符串。我建议从简单的东西开始,而不是从表单字段中提取,以消除任何外部问题。一旦邮件发送,然后开始添加其他部分。
public static string mailServer = 'IP address or host name of mail server'
public static void Send()
{
string subject = "test subject";
string address = "test@somedomain.com";
string body = "some mail body";
MailMessage mm = new MailMessage();
mm.From = new MailAddress("no-reply@domain.net"); //on behalf of
mm.To.Add(new MailAddress(address));
mm.IsBodyHtml = true;
mm.Subject = subject;
mm.Body = body;
SmtpClient server = new SmtpClient(mailServer);
server.Send(mm);
}
}
答案 1 :(得分:2)
string5和string6是邮件服务器上的电子邮件凭据(用户名和密码)。你应该更了解我们; - )
答案 2 :(得分:1)
您需要使用邮件服务器的名称/域信息更新smtpClinet.Host。需要使用可以访问邮件服务器的用户的用户名和密码更新凭据。有时这可以省略。