인트라넷에서 메일을 보내려고합니다. 텍스트 상자에서 값을 받아들이고 각 필드로 전달할 페이지를 디자인했습니다.SMTP 메일이 작동하지 않습니다.
이합니다 (<tr>
및 <td>
태그를 무시하십시오) 내 프런트 엔드 코드입니다 : 나는에 다음 값을 입력 할 때 이제
protected void btnSMail_Click(object sender, EventArgs e)
{
string smtpadd = txtSMTP.Text;
try
{
if (smtpadd != "" && smtpadd != null)
{
MailMessage mm = new MailMessage();
SmtpClient sc = new SmtpClient(txtSMTP.Text);
if (!fupAttach.HasFile)
{
FileStream fs = new FileStream("D:\\DEV\\New.xml", FileMode.Open, FileAccess.Read);
Attachment attch = new Attachment(fs, "License Generation in XML", MediaTypeNames.Application.Octet);
mm.Attachments.Add(attch);
}
//sc.Host = "10.8.4.118";
sc.Port = 25;
sc.EnableSsl = false; // runtime encrypt the SMTP communications using SSL
mm.To.Add(new MailAddress(txtTo.Text, txtReceiver.Text));
mm.From = new MailAddress(txtMailAdd.Text, txtFrom.Text);
mm.Subject = txtSub.Text;
//mm.To= new MailAddress(txtTo.Text);
mm.Body = txtBody.Text;
if (fupAttach.HasFile)
{
String FileName = fupAttach.PostedFile.FileName;
Attachment mailAttachment = new Attachment(FileName, MediaTypeNames.Application.Octet);
mm.Attachments.Add(mailAttachment);
}
lblMailFail.Text = "Mail Successfully Sent";
sc.Send(mm);
}
else
{
lblMailFail.Text = "Enter an SMTP IP";
}
}
:
<td>
FROM
</td>
<td>
<asp:TextBox ID="txtFrom" runat="server" CssClass="Textbox1" Width="414px"></asp:TextBox>
</td>
<td>
SENDER MAIL
</td>
<td>
<asp:TextBox ID="txtMailAdd" runat="server" CssClass="Textbox1" Width="414px"></asp:TextBox>
<td>
SMTP IP
</td>
<td>
<asp:TextBox ID="txtSMTP" runat="server" CssClass="Textbox1" Width="414px"></asp:TextBox>
<td>
RECEIVER
</td>
<td>
<asp:TextBox ID="txtReceiver" runat="server" CssClass="Textbox1" Width="414px"></asp:TextBox>
<td>
TO MAIL
</td>
<td>
<asp:TextBox ID="txtTo" runat="server" CssClass="Textbox1" Width="414px"></asp:TextBox>
이 내 백엔드 코드 텍스트 상자
Sender Mail: [email protected]
SMTP ID: 10.8.4.2
Receiver Mail: [email protected]
오류 메시지가 나타날 수 있습니다.
System.Net.Mail.SmtpFailedRecipientException: Mailbox unavailable. The server response was: 5.7.1 Unable to relay for [email protected] at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, SmtpFailedRecipientException& exception) at System.Net.Mail.SmtpClient.Send(MailMessage message) at Lic_Gen.btnSMail_Click(Object sender, EventArgs e)
누군가가 나를 안내 할 수 있습니까?
가 오른쪽 SMTP 포트를 사용하는지 확인을 찾을 수 있습니다. –
SMTP 서버가 릴레이를 허용하지 않습니다 (즉, 이메일을 다른 서버로 전달). 중계를 허용하거나 다른 SMTP 서버로 전환하도록 SMTP 서버를 구성해야합니다. – jgauffin
요점은, 보내기 전에 성공적으로 전송되었다고 말하지 마십시오. 또한 메일 서버가 다운 될 수 있다는 사실을 허용하기 위해 try catch에 넣으십시오. 그런 다음이 코드가 작동하지 않으면 중단됩니다. –