Gmail을 통해 이메일을 보내는 winforms 앱이 있습니다. 잘 작동하지만 한 경우에는 전송이 실패하고 위의 오류가 발생합니다. 내 응용 프로그램이 RDP 연결을 통해 액세스하는 컴퓨터에서 실행 중일 때 발생합니다. 지금까지 성공하지 못했습니다.
내 코드는 다음과 같습니다. (이 코드는이 코드를 제외한 모든 경우에서 작동합니다.)
string fromAddress = txtFrom.Text.Trim();
string toAddress = txtTo.Text.Trim();
string fromPassword = ePassword;
string subject = txtSubject.Text;
string body = txtMessage.Text;
var smtp = new SmtpClient
{
Host = "smtp.gmail.com",
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
//Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
Credentials = new NetworkCredential(fromAddress, fromPassword)
};
//using (var message = new MailMessage(fromAddress, toAddress)
using (var message = new MailMessage()
{
From = new MailAddress(fromAddress, eDisplayName),
Subject = subject,
Body = body
})
{
// Check for recipiens
if (txtTo.Text.Trim() != "")
{
foreach (string email in txtTo.Text.Split(';'))
{
message.To.Add(email.Trim());
}
}
// check for copies
if (txtCopy.Text.Trim() != "")
{
foreach (string email in txtCopy.Text.Split(';'))
{
message.CC.Add(email.Trim());
}
}
// check for blind copy
if (txtBlindCopy.Text.Trim() != "")
{
foreach (string email in txtBlindCopy.Text.Split(';'))
{
message.Bcc.Add(email.Trim());
}
}
//check for attachments
for (int i = 0; i < clbAttachments.Items.Count; i++)
{
if (clbAttachments.GetItemChecked(i) == true)
{
Attachment attachment = new Attachment(clbAttachments.Items[i].ToString());
message.Attachments.Add(attachment);
}
}
smtp.Send(message);
return true;
답을 찾았습니다. 내 코드에서 포트를 25로 변경했고 메시지가 전송되었습니다! 모든 변경 사항을 OS에 롤백하고 포트 변경 만 수행해야하는 유일한 작업인지 확인했습니다. 누군가가 이것을 유용하게 찾을 수 있기를 바랍니다.
편집 : 포트 25는 비보안 포트입니다. 제 경우에는 신경 쓰지 않아서 문제가 해결되었습니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다