これは私が1and1でホストされているウェブサイトのメール設定とreCAPTCHAのプロキシの使用コードです:
の1- Web.configファイル(そこに置く場合のみ動作します!)
<system.net>
<mailSettings>
<smtp from="[email protected]">
<network host="smtp.1and1.com" port="25" userName="[email protected]" password="mypassword"/>
</smtp>
</mailSettings>
<defaultProxy>
<proxy usesystemdefault = "false" bypassonlocal="false" proxyaddress="http://ntproxyus.lxa.perfora.net:3128" />
</defaultProxy>
</system.net>
マイコン内の専用のアクションの中で:
// ouside the action I've defined the response
private class gapi {public bool success{get;set;}}
public bool SendMail(string firstname, string lastname, string email, string message, string grecaptcha)
{
SmtpClient smtp = new SmtpClient("smtp.1and1.com");
MailMessage mail = new MailMessage();
mail.From = new MailAddress(email);
mail.To.Add("[email protected]");
mail.Subject = firstname + " " + lastname;
mail.Body = message;
try
{
using (var client = new WebClient())
{
var values = new NameValueCollection();
values["secret"] = "6LcEnQYTAAAAAOWzB44-m0Ug9j4yem9XE4ARERUR";
values["response"] = grecaptcha;
values["remoteip"] = Request.UserHostAddress;
var response = client.UploadValues("https://www.google.com/recaptcha/api/siteverify","POST", values);
bool result = Newtonsoft.Json.JsonConvert.DeserializeObject<gapi>((Encoding.Default.GetString(response) as string)).success;
if(!result) return "Something is wrong)";
}
//... verify that the other fields are ok and send your mail :)
smtp.Send(mail);
}
catch (Exception e) { return "Something is wrong)"; }
return "Okey :)";
}
希望します。
recaptchaのWebサイトには、展開したサーバーからアクセスできますか? –
@ M.Babcockどうすればこのことを確認できますか?私はreCaptchaコントロールを参照して、アクセス可能であると想定しました。 – Kalyan