Click here to Skip to main content
15,885,213 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Why the error is given SmtpMail.Send(objMail) in the below code?

ASP.NET
<%@ Page Language="VB" EnableSessionState="False" EnableViewState="False" Trace="False" Debug="True"%>
<%@ Import Namespace="System.Web.Mail" %>
<script  runat="server">
VB
Sub Page_Load(Sender as Object, E as EventArgs)
    If Page.IsPostBack Then
        lblResponse.Text = "Your email has been sent."
    End If
End Sub
     
Sub btn_Click(sender as Object, e as System.EventArgs)
  If  Request.Form("Email") <> "" Then
    Dim objMail As New MailMessage()
    objMail.From = "contact@kamnatrust.com"
    objMail.To = Request.Form("Email")
    objMail.Subject = Request.Form("Subject")
    objMail.Body = Request.Form("Message")
    objMail.BodyFormat = MailFormat.Text
    SmtpMail.SmtpServer = " smtp.kamnatrust.com"
    SmtpMail.Send(objMail)
  Else
    lblResponse.Text = "Please enter an email address."
  End If
End Sub

ASP.NET
</script>
<html>
<head>
<style>
.main {font-family:Verdana; font-size:12px;}
.title {font-family:Verdana; font-size:18px; font-weight:bold;}
</style>
</head>
<body>
Send email from  
an ASP.NET page

<br><br><asp:Label class="main" id="lblResponse" runat="server"/>
 
<form method="POST" name="MainForm"  runat="server">
<table>
  <tr>
    <td class="main" align="right">Email:</td> <br>
    <td class="main"><input type="text" class="main" name="Email" value=""></td>
  </br></tr>
  <tr>
    <td class="main" align="right"> 
    Subject:</td>
    <td class="main"><input type="text" class="main" name="Subject" value=""></td>
  </tr>
  <tr>
    <td class="main" align="right" valign="top">Message:</td>
    <td class="main"><textarea name="Message" cols="50" rows="8"></textarea></td>
  </tr>

  <tr>
    <td class="main"> </td>
    <td class="main"><input type="Submit" id="btnSubmit"  önServerClick="btn_Click" value="Send"  runat="server" /></td>
  </tr>
</table>
</form>
</body>
</html></br></br>
Posted
Updated 31-Oct-11 1:11am
v2
Comments
Anil Honey 206 31-Oct-11 7:02am    
You want in c# or vb.net
Janardan Pandey 31-Oct-11 7:04am    
any one you help me
Dylan Morley 31-Oct-11 7:09am    
What is the error?

1 solution

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Collections;
using System.Text;
using System.Data.SqlClient;
using System.Web.Mail;
using System.Net;
using System.Net.Mail;
using System.Drawing;
using System.IO;


  System.Net.Mail.MailMessage obj = new System.Net.Mail.MailMessage();

  SmtpClient serverobj = new SmtpClient();
            serverobj.Credentials = new NetworkCredential("anilmeets4u@gmail.com", "archuanil");
            serverobj.Port = 587;
            serverobj.Host = "smtp.gmail.com";
            serverobj.EnableSsl = false;
            obj = new System.Net.Mail.MailMessage();
            obj.From = new MailAddress("anilmeets4u@gmail.com", "AgileLearning.com", System.Text.Encoding.UTF8);
            obj.To.Add(ASPxtxtToUser.Text);
            obj.CC.Add(ASPxTexttoCc.Text);
            obj.Priority = System.Net.Mail.MailPriority.High;
            obj.Subject = txtSubject.Text;
            string date = DateTime.Now.ToString();
            obj.Body = ASPxMemo1.Text;
            serverobj.Send(obj);
            lblsend.Text = "Your Message Send Sucessfully";

Try this in Button Code.


Regards,

Anilkumar.D
 
Share this answer
 
v2
Comments
Janardan Pandey 2-Nov-11 4:14am    
Is any procedure to send feedback bethout user id and password?Only i want to give domain name and recivers address, to address, cc address and bcc

obj.From = new MailAddress("anilmeets4u@gmail.com", "AgileLearning.com", System.Text.Encoding.UTF8);

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900