我想使用asp.net
创建与我们联系表单。我正在尝试发送带附件的邮件,但它给了我以下错误/异常 -
用户不在本地;请尝试不同的路径。服务器响应为:发件人地址对您的登录无效。检查您的电子邮件程序设置。
我需要来自地址必须是TextBox
电子邮件地址中的用户类型,我还想知道是否有任何插件来发送邮件?
以下是我的代码..需要帮助
背后的代码
protected void btnsubmit_Click(object sender, EventArgs e)
{
try
{
MailMessage Msg = new MailMessage();
//Sender e-mail address.
Msg.From = new MailAddress(txtemail.Text);
//Recipient e-mail address.
Msg.To.Add("admin@comapany.com");
//Meaages Subject
Msg.Subject = "";
System.Text.StringBuilder sb = new StringBuilder();
sb.Append("Name :" + txtname.Text + "\r\n");
sb.Append("Contact:" + txtcontact.Text + "\r\n");
sb.Append("Email:" + txtemail.Text + "\r\n");
sb.Append("Message:" + txtmessage.Text + "\r\n");
if (FileUpload1.HasFile)
{
string FileName = FileUpload1.PostedFile.FileName;
Msg.Attachments.Add(new Attachment(FileUpload1.PostedFile.InputStream, FileName));
}
Msg.Body = sb.ToString();
// SMTP server IP.
SmtpClient smtp = new SmtpClient();
//smtp.Host = "smtp.gmail.com";
//smtp.Port = 25;
smtp.Host = "webmail.sarvajteq.com";
smtp.Port = 25;
smtp.Credentials = new System.Net.NetworkCredential("******","*********");
smtp.EnableSsl = false;
smtp.Send(Msg);
//Mail Message
Response.Write("<Script>alert('Thanks for posting your resume us,our team will be contact you as soon as possible')</Script>");
// Clear the textbox values
txtname.Text = "";
txtcontact.Text = "";
txtemail.Text = "";
txtmessage.Text = "";
}
catch (Exception ex)
{
txtname.Text = "";
txtcontact.Text = "";
txtemail.Text = "";
txtmessage.Text = "";
Response.Write(ex.Message);
}
}
ASPX
<form id="form1" runat="server">
<div>
<fieldset style="width: 400px;">
<legend>Career Form</legend>
<table>
<tr>
<td>
Name
</td>
<td>
<asp:TextBox ID="txtname" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Conatct Number
</td>
<td>
<asp:TextBox ID="txtcontact" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Email
</td>
<td>
<asp:TextBox ID="txtemail" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Message
</td>
<td>
<asp:TextBox ID="txtmessage" runat="server" TextMode="MultiLine"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Resume Upload
</td>
<td>
<asp:FileUpload ID="FileUpload1" runat="server" />
</td>
</tr>
<tr>
<td style="text-align:center" colspan="2">
<asp:Button ID="btnsubmit" runat="server" Text="Submit" OnClick="btnsubmit_Click"
Font-Bold="True" Font-Size="Medium" Width="200px" />
</td>
</tr>
</table>
</fieldset>
</div>
</form>