Im trying to make an email form in my website (its a local host for now),
When I run my code, and press on “send”, its throwing me this exception :
System.Runtime.InteropServices.COMException: ??? ?????? “SendUsing”
???? ?÷?.
what could be the problem?
this is my code :
<%@ Import Namespace="System.Web.Mail" %>
<script language="c#" runat="server">
protected void Button2_Click(object sender, EventArgs e)
{
MailMessage msg = new MailMessage();
msg.To = "XXX@gmail.com";
msg.From = EmailTxt.Text;
msg.Subject = "Fun With Daniel Email: from" + UsernameTxt.Text;
msg.Body = MessegeBox.Text;
msg.BodyFormat = MailFormat.Text;
ErrorMessege.Text = "Sending..";
System.Web.Mail.SmtpMail.Send(msg);
ErrorMessege.Text = "The Email Sent successfully!";
}
</script>
<td>
<asp:TextBox ID="UsernameTxt" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator10" runat="server" ErrorMessage="Please insert a Username"
ControlToValidate="UsernameTxt" ForeColor="Red" Display="None"
SetFocusOnError="True"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
Email
</td>
<td>
<asp:TextBox ID="EmailTxt" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator11" runat="server" ErrorMessage="Please insert Password"
ControlToValidate="EmailTxt" ForeColor="Red" Display="None"
SetFocusOnError="True"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
Messege
</td>
<td>
<asp:TextBox ID="MessegeBox" runat="server" Height="100px" TextMode="MultiLine"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="You have to write a messege"
ControlToValidate="MessegeBox" ForeColor="Red" Display="None"
SetFocusOnError="True"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
<asp:Button ID="Button2" runat="server" Text="Login" OnClick="Button2_Click" />
</td>
<td>
<asp:Label ID="ErrorMessege" runat="server" ForeColor="Red"></asp:Label>
<asp:ValidationSummary ID="ValidationSummary2" runat="server" ForeColor="Red" />
</td>
</tr>
System.Web.Mailrequires CDONTs and CDOSYS, so that’s the first thing you’ll have to look at in this case. See this site for solutions to common problems.The fact that there’s a whole site dedicated to problems with this namespace should tell you that you’re better off using
System.Net.Mail, which is a native SMTP implementation and does not rely on COM components. Unless you’re using .NET 1.x, you should switch to it if at all possible.