C#和Godaddy服务器的电子邮件发送错误 [英] Email sending error with c# and Godaddy server
问题描述
我正在使用Goodaddy的托管服务,mi复制是在c#中进行的,问题是在发送电子邮件时,这是我的代码
Hi i am using the hosting from goodaddy, mi aplication was made in c#, the problem is when send an email, this is my code
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,下一个错误是
my email that send the email is gmail, the error is the next
System.Net.Mail.SmtpException:发送邮件失败---> System.Net.WebException:无法连接到远程服务器---> System.Net .Sockets.SocketException:试图以System.Net.Sockets.Socket.DoConnect(EndPoint endP的访问权限74.125.199.109:587禁止的方式访问套接字ointSnapshot,位于System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure,Socket s4,Socket s6,Socket&套接字,IPAddress&地址,ConnectSocketState状态,IAsyncResult asyncResult,Exception&异常)-内部异常堆栈跟踪的结尾--在System.Net.PooledStream处System.Net.ServicePoint.GetConnection(PooledStream PooledStream,对象所有者,布尔异步,IPAddress&地址,Socket&abortSocket,Socket&abortSocket6) System.Net.Connection.ool上的.Activate(Object owningObject,布尔异步,GeneralAsyncDelegate asyncCallback)System.Net.Connection.Pool.GetConnection(Object owningObject,GeneralAsyncDelegate asyncCallback)在System.Net。 System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint)在System.Net.Mail.SmtpClient.GetConnection()在System.Net.Mail.SmtpClient.Send(MailMessage消息)处的Mail.SmtpConnection.GetConnection(ServicePoint servicePoint)- -内部异常堆栈跟踪的结尾---在System.Net.Mail.SmtpClient.Send(MailMessage消息)在Core.EmailManager.sendEmail(EmailDto emailDto)
System.Net.Mail.SmtpException: Failure sending mail. ---> System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: An attempt was made to access a socket in a way forbidden by its access permissions 74.125.199.109:587 at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception) --- End of inner exception stack trace --- at System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6) at System.Net.PooledStream.Activate(Object owningObject, Boolean async, GeneralAsyncDelegate asyncCallback) at System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback) at System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate 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) --- End of inner exception stack trace --- at System.Net.Mail.SmtpClient.Send(MailMessage message) at Core.EmailManager.sendEmail(EmailDto emailDto)
可能是什么是问题吗?
推荐答案
我解决了,我希望这种帮助对某人有所帮助,代码在这里:
I solved, I hope that this aswer helps somebody, this the code is here:
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 = false;
client.UseDefaultCredentials = false;
client.Port = 25;
client.Host = "relay-hosting.secureserver.net";
client.Send(message);
}
catch (Exception e) {
return new ResponseDto
{
message = e.ToString()
,
Success = false
};
}
return new ResponseDto
{
message = "success",
Success = true
};
}
问题是其他中继/ smtp服务器无法正常工作从我们的托管。而且我不需要指定密码。我更改了端口和主机,这是对我有帮助的链接
the problem was that other relay/smtp servers will not work from our hosting. and i don't need specify the password. and i change the port and the host, this is the link that help me
https://au.godaddy.com/community/Developer-Cloud-Portal/Unable从C / net应用程序从网站/ td-p / 2394发送电子邮件
https://au.godaddy.com/community/Developer-Cloud-Portal/Unable-to-send-email-from-C-net-application-from-website/td-p/2394
这篇关于C#和Godaddy服务器的电子邮件发送错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!