我正在尝试在Intranet上发送邮件。我设计了一个页面,其中的值将从文本框中接受,并传递到相应的字段。
这是我的前端代码(请忽略<tr>
和<td>
代码):
<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>
这是我的后端代码:
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";
}
}
现在,当我尝试在文本框中输入以下值时
Sender Mail: xyz@sdc.ba.co.in
SMTP ID: 10.8.4.2
Receiver Mail: xyz@sdc.ba.co.in
我收到错误
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)
有人可以指导我哪里出错了吗?
答案 0 :(得分:2)
这是一个SMTP配置问题,与您的C#代码无关。
答案 1 :(得分:2)
邮件服务器不允许您(或您的IP)将邮件发送到指定的电子邮件地址。您可以对邮件服务器here进行详细测试。
您可以在Eudora website上找到有关邮件中继的更多信息(大部分信息适用于所有邮件服务器)