【发布时间】:2017-05-05 07:38:51
【问题描述】:
您好,我正在使用来自 goodaddy 的托管,mi 应用程序是用 c# 制作的,问题是发送电子邮件时,这是我的代码
public ResponseDto sendEmail(EmailDto emailDto) {
try
{
MailMessage message = new MailMessage();
SmtpClient client = new SmtpClient();
message.From = new MailAddress("mail@gmail.com");
message.Subject = "have a new mail";
message.Body = "info: \n "
+ "name: " + emailDto.Name
+ "\mail: "+ emailDto.Email + "\nMessage: " +
emailDto.Message;
message.To.Add("mail@hotmail.com");
client.EnableSsl = true;
client.UseDefaultCredentials = false;
client.Port = 587;
client.Host = "smtp.gmail.com";
client.Credentials = new System.Net.NetworkCredential("mail@gmail.com", "(password");
client.Send(message);
}
catch (Exception e) {
return new ResponseDto
{
message = e.ToString()
,
Success = false
};
}
return new ResponseDto
{
message = "success",
Success = true
};
}
我发送邮件的邮箱是gmail,错误是下一个
System.Net.Mail.SmtpException:发送邮件失败。 ---> System.Net.WebException:无法连接到远程服务器 ---> System.Net.Sockets.SocketException:尝试以访问权限 74.125.199.109:587 禁止的方式访问套接字在 System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) 在 System.Net.ServicePoint.ConnectSocketInternal (Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception) --- 内部异常堆栈跟踪结束 --- 在 System.Net.PooledStream.Activate(Object owningObject 的 System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6) , 布尔异步, GeneralAsyncDelegate asyncCallback) 在 System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback) 在 System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate e asyncCallback, Int32 creationTimeout) at System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint) at System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint) at System.Net.Mail.SmtpClient.GetConnection() at System.Net .Mail.SmtpClient.Send(MailMessage message) --- 内部异常堆栈跟踪结束 --- 在 System.Net.Mail.SmtpClient.Send(MailMessage message) 在 Core.EmailManager.sendEmail(EmailDto emailDto)
可能是什么问题?
【问题讨论】:
-
显然,you cannot do that on GoDaddy 使用共享主机帐户。
-
或者你可以尝试using GMail API而不是SMTP
-
@KenY-N y 看到了这篇文章,也许我需要设置一个来自 godaddy 的电子邮件
-
我解决了,几分钟后我会给出答案谢谢大家!