2012-12-19 4 views
0

인트라넷에서 메일을 보내려고합니다. 텍스트 상자에서 값을 받아들이고 각 필드로 전달할 페이지를 디자인했습니다.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)

누군가가 나를 안내 할 수 있습니까?

+0

가 오른쪽 SMTP 포트를 사용하는지 확인을 찾을 수 있습니다. –

+0

SMTP 서버가 릴레이를 허용하지 않습니다 (즉, 이메일을 다른 서버로 전달). 중계를 허용하거나 다른 SMTP 서버로 전환하도록 SMTP 서버를 구성해야합니다. – jgauffin

+0

요점은, 보내기 전에 성공적으로 전송되었다고 말하지 마십시오. 또한 메일 서버가 다운 될 수 있다는 사실을 허용하기 위해 try catch에 넣으십시오. 그런 다음이 코드가 작동하지 않으면 중단됩니다. –

답변

2

이것은 SMTP 구성 문제이며 C# 코드와 관련이 없습니다.

+0

내 코드가 완벽하게 괜찮습니까? : P – Esha

+0

완벽하다고는 말할 수 없지만 SMTP 구성이 맞으면 제대로 작동합니다. D – ChrisBint

+0

: P 하하. 괜찮아. 감사. 어떻게 내 SMTP 구성이 맞는지 아닌지 확인하겠습니까? : P – Esha

2

메일 서버는 사용자 (또는 귀하의 IP)가 지정된 전자 메일 주소로 메일을 보낼 수 없도록합니다. 메일 서버 here에 대한 자세한 테스트를 수행 할 수 있습니다.

당신은 Eudora website에 메일 릴레이에 대한 자세한 정보를 (정보의 대부분은 모든 메일 서버에 적용)

관련 문제