0

I'm trying to send mail on intranet. I have designed a page where the values will be accepted from textboxes, and passed to the respective fields.

This is my front end code (Please ignore the <tr> and <td> tags):

<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>

This is my backend code:

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";
        }
    }

Now when I try to enter the following values in the textbox

Sender Mail: xyz@sdc.ba.co.in
SMTP ID: 10.8.4.2
Receiver Mail: xyz@sdc.ba.co.in

I get an error

System.Net.Mail.SmtpFailedRecipientException: Mailbox unavailable. The server response was: 5.7.1 Unable to relay for xyz@sdc.ba.co.in 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)

Can someone please guide me where am I going wrong?

4

2 回答 2

2

这是一个 SMTP 配置问题,与您的 C# 代码无关。

于 2012-12-19T10:22:31.733 回答
2

邮件服务器不允许您(或您的 IP)向指定的电子邮件地址发送邮件。您可以在此处对邮件服务器进行详细测试。

您可以在Eudora 网站上找到有关邮件中继的更多信息(大部分信息适用于所有邮件服务器)

于 2012-12-19T10:22:55.700 回答