MVCサイトに新しい電子メールによる確認方法を追加しようとしています。確認メールが届きます。smtpエラーでGmailを使用しているASP.NET:「接続した相手が正しく応答しなかったため接続に失敗しました。」
"A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 66.102.1.108:587".
私が使用したコードは次のとおりです:
using ATMProject.Models;
using Microsoft.AspNet.Identity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Mail;
using System.Security.Policy;
using System.Web;
using System.Web.Mvc;
namespace ATMProject.Services
{
public class SendEmailConfirmation
{
public string email { get; set; }
public string fullname { get; set; }
public string username { get; set; }
public string random { get; set; }
public SendEmailConfirmation(string Email, string Fullname,
string Username, string Random)
{
email = Email;
fullname = Fullname;
username = Username;
random = Random;
}
public void sendEmail()
{
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new
System.Net.NetworkCredential("[email protected]", "123456");
smtp.EnableSsl = true;
MailMessage msg = new MailMessage();
#region Msg
msg.Subject = "Hello " + fullname;
msg.Body = "Hello " + fullname +
"Thanks for Registering in Budgetize...Your Account Details are given below:";
msg.Body += "<tr>";
msg.Body += "<td>User Name :" + username + "</td>";
msg.Body += "</tr>";
msg.Body += "<tr>";
msg.Body += "<td>Activation Number :" + random + "</td>";
msg.Body += "</tr>";
msg.Body += "<tr>";
msg.Body += "<td>Thanking</td><td>Team Budgetize</td>";
msg.Body += "</tr>";
#endregion
string toAddress = email; // Add Recepient address
msg.To.Add(toAddress);
string fromAddress = "\"Budgetize \" <[email protected]>";
msg.From = new MailAddress(fromAddress);
msg.IsBodyHtml = true;
try {smtp.Send(msg);}
catch (Exception ex) {throw;}
}
}
}
実際のパスワードをそこに入れないことを願っています。 – Steve