send email after insert record

i have this code and would like to send email after submiting this.   i am used to asp classic and dont know how to send email in dot net.

any ideas?


<MM:Insert
runat="server"
CommandText='<%# "INSERT INTO dbo.coachjobs (ClubName, Info, ContactName, ContactPhone, ContactEmail, Submitted, approval) VALUES (@ClubName, @Info, @ContactName, @ContactPhone, @ContactEmail, @Submitted, @approval)" %>'
ConnectionString='<%# System.Configuration.ConfigurationSettings.AppSettings("MM_CONNECTION_STRING_iysa") %>'
DatabaseType='<%# System.Configuration.ConfigurationSettings.AppSettings("MM_CONNECTION_DATABASETYPE_iysa") %>'
Expression='<%# Request.Form("MM_insert") = "form1" %>'
CreateDataSet="false"
SuccessURL='<%# "coachingjobs.aspx?message=The Job Request has been added for approval" %>'
Debug="true"
><Parameters>
  <Parameter Name="@ClubName" Value='<%# IIf((Request.Form("ClubName") <> Nothing), Request.Form("ClubName"), "") %>' Type="VarChar" />  
  <Parameter Name="@Info" Value='<%# IIf((Request.Form("Info") <> Nothing), Request.Form("Info"), "") %>' Type="VarChar" />  
  <Parameter Name="@ContactName" Value='<%# IIf((Request.Form("ContactName") <> Nothing), Request.Form("ContactName"), "") %>' Type="VarChar" />  
  <Parameter Name="@ContactPhone" Value='<%# IIf((Request.Form("ContactPhone") <> Nothing), Request.Form("ContactPhone"), "") %>' Type="VarChar" />  
  <Parameter Name="@ContactEmail" Value='<%# IIf((Request.Form("ContactEmail") <> Nothing), Request.Form("ContactEmail"), "") %>' Type="VarChar" />  
  <Parameter Name="@Submitted" Value='<%# IIf((Request.Form("submitted") <> Nothing), Request.Form("submitted"), "") %>' Type="DateTime" />  
  <Parameter Name="@approval" Value='<%# IIf((Request.Form("approval") <> Nothing), Request.Form("approval"), "") %>' Type="Int" />  
</Parameters>
</MM:Insert>
LVL 1
gianitooAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AGBrownCommented:
Have a look at System.Mail, its a .NET wrapper for CDONTS, I think.

You would use something like:

      MailMessage msg;
      msg = new MailMessage();
      msg.To = "you@you.com";
      msg.From = "me@me.com";
      msg.Subject = "message title";
      msg.Body = "message";
      msg.BodyFormat = MailFormat.Text;
      SmtpMail.SmtpServer = "127.0.0.1";
      SmtpMail.Send(msg);

You would then put this in the appropriate event handler for the click event or button press that you are using.

Andy
0
gianitooAuthor Commented:
this is how my form looks like.....do i call it from here

<form method="post" name="form1" runat="server">
                        <table align="center">
                          <tr valign="baseline">
                            <td align="right" nowrap class="aaaa">ClubName:</td>
                            <td><asp:textbox id="ClubName" TextMode="SingleLine" Columns="32" runat="server" />                      
                            </td>
                          </tr>
                          <tr valign="baseline">
                            <td align="right" valign="top" nowrap class="aaaa">Info:</td>
                            <td><asp:textbox id="Info" TextMode="MultiLine" Columns="32" runat="server" Rows="5" />                      
                            </td>
                          </tr>
                          <tr valign="baseline">
                            <td align="right" nowrap class="aaaa">ContactName:</td>
                            <td><asp:textbox id="ContactName" TextMode="SingleLine" Columns="32" runat="server" />                      
                            </td>
                          </tr>
                          <tr valign="baseline">
                            <td align="right" nowrap class="aaaa">ContactPhone:</td>
                            <td><asp:textbox id="ContactPhone" TextMode="SingleLine" Columns="32" runat="server" />                      
                            </td>
                          </tr>
                          <tr valign="baseline">
                            <td align="right" nowrap class="aaaa">ContactEmail:</td>
                            <td><asp:textbox id="ContactEmail" TextMode="SingleLine" Columns="32" runat="server" />                      
                            </td>
                          </tr>
                          <tr valign="baseline">
                            <td nowrap align="right">&nbsp;</td>
                            <td><input name="approval" type="hidden" id="approval" value="0" /></td>
                          </tr>
                          <tr valign="baseline">
                            <td nowrap align="right">&nbsp;</td>
                            <td><input type="submit" value="Insert record"></td>
                          </tr>
                        </table>
                        <input type="hidden" name="MM_insert" value="form1">
                        <input name="submitted" type="hidden" id="submitted" value="<%=now%>" />
                      </form>
0
AGBrownCommented:
How are you submitting your record to be inserted?
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

gianitooAuthor Commented:
i just hit submit and it automatically runs the code i pasted above
0
AGBrownCommented:
I think you are going to have to intercept the submit event, run the insert code yourself, and then send the email.

What development environment are you using? Is it .NET 2.0 in Visual Studio 2005 (Web Developer, Professional?)?

Andy
0
stevegingellCommented:
All you have to do is put the mailing process after you're done inserting the records into the database. Like AGBrown mentioned you need a click event when you hit submit. The event wuld process the database code and email the results.

Make sure to import this namespace. So it ould go something like this:
Imports System.Web.Mail

Then inside your AddToDatabase method add the following code:

Dim objMail As New MailMessage
        objMail.From = "you@domain.com"
        objMail.To = "someone@domain.com"
        objMail.Subject = "Your subject header"
        objMail.BodyFormat = MailFormat.Html
        objMail.Body &= "<p><p><font face=Verdana, size=2, color=black>Dear Whoever,</p><p><p>"
        ................
        SmtpMail.SmtpServer = "mail server ip"
        SmtpMail.Send(objMail)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AGBrownCommented:
gianitoo,

Did you have any success? Let us know if you want any more help.

Andy
0
gianitooAuthor Commented:
i could not get it working...is there a way that from this code you can insert your code and get it working?

<%@ Register TagPrefix="cspb" Namespace="Coalesys.PanelBar"
Assembly="Coalesys.PanelBar" %>
<%@ Page language="VB" %>

<% @Import Namespace="System.Web.Mail" %>


<%@ Register TagPrefix="MM" Namespace="DreamweaverCtrls" Assembly="DreamweaverCtrls,version=1.0.0.0,publicKeyToken=836f606ede05d46a,culture=neutral" %><MM:Insert
runat="server"
CommandText='<%# "INSERT INTO dbo.coachjobs (ClubName, Info, ContactName, ContactPhone, ContactEmail, Submitted, approval) VALUES (@ClubName, @Info, @ContactName, @ContactPhone, @ContactEmail, @Submitted, @approval)" %>'
ConnectionString='<%# System.Configuration.ConfigurationSettings.AppSettings("MM_CONNECTION_STRING_iysa") %>'
DatabaseType='<%# System.Configuration.ConfigurationSettings.AppSettings("MM_CONNECTION_DATABASETYPE_iysa") %>'
Expression='<%# Request.Form("MM_insert") = "form1" %>'
CreateDataSet="false"
SuccessURL='<%# "coachingjobs.aspx?message=The Job Request has been added for approval" %>'
Debug="true"
><Parameters>
  <Parameter Name="@ClubName" Value='<%# IIf((Request.Form("ClubName") <> Nothing), Request.Form("ClubName"), "") %>' Type="VarChar" />  
  <Parameter Name="@Info" Value='<%# IIf((Request.Form("Info") <> Nothing), Request.Form("Info"), "") %>' Type="VarChar" />  
  <Parameter Name="@ContactName" Value='<%# IIf((Request.Form("ContactName") <> Nothing), Request.Form("ContactName"), "") %>' Type="VarChar" />  
  <Parameter Name="@ContactPhone" Value='<%# IIf((Request.Form("ContactPhone") <> Nothing), Request.Form("ContactPhone"), "") %>' Type="VarChar" />  
  <Parameter Name="@ContactEmail" Value='<%# IIf((Request.Form("ContactEmail") <> Nothing), Request.Form("ContactEmail"), "") %>' Type="VarChar" />  
  <Parameter Name="@Submitted" Value='<%# IIf((Request.Form("submitted") <> Nothing), Request.Form("submitted"), "") %>' Type="DateTime" />  
  <Parameter Name="@approval" Value='<%# IIf((Request.Form("approval") <> Nothing), Request.Form("approval"), "") %>' Type="Int" />  
</Parameters>
</MM:Insert>
<MM:DataSet
id="general"
runat="Server"
IsStoredProcedure="false"
ConnectionString='<%# System.Configuration.ConfigurationSettings.AppSettings("MM_CONNECTION_STRING_iysa") %>'
DatabaseType='<%# System.Configuration.ConfigurationSettings.AppSettings("MM_CONNECTION_DATABASETYPE_iysa") %>'
CommandText='<%# "SELECT *  FROM dbo.coachjobs  WHERE approval = 1 AND Submitted <= GETDATE() AND Submitted >= DATEADD(d, -100, GETDATE())  ORDER BY Submitted DESC" %>'
Debug="true"
></MM:DataSet>
<MM:PageBind runat="server" PostBackBind="true" />
<script runat="server">

Sub Page_Load(Sender As Object, E As EventArgs)

LeftNav.LoadState(Server.MapPath("./") + "\panel.pbs")

If LeftNav.DetectedBrowser = Coalesys.PanelBar.GenerateConstants.NN4DHTML
Response.ContentEncoding = Encoding.Default
End If

End Sub
</script>


<form method="post" name="form1" runat="server">
                        <table align="center">
                          <tr valign="baseline">
                            <td align="right" nowrap class="aaaa">ClubName:</td>
                            <td><asp:textbox id="ClubName" TextMode="SingleLine" Columns="32" runat="server" />                      
                            </td>
                          </tr>
                          <tr valign="baseline">
                            <td align="right" valign="top" nowrap class="aaaa">Info:</td>
                            <td><asp:textbox id="Info" TextMode="MultiLine" Columns="32" runat="server" Rows="5" />                      
                            </td>
                          </tr>
                          <tr valign="baseline">
                            <td align="right" nowrap class="aaaa">ContactName:</td>
                            <td><asp:textbox id="ContactName" TextMode="SingleLine" Columns="32" runat="server" />                      
                            </td>
                          </tr>
                          <tr valign="baseline">
                            <td align="right" nowrap class="aaaa">ContactPhone:</td>
                            <td><asp:textbox id="ContactPhone" TextMode="SingleLine" Columns="32" runat="server" />                      
                            </td>
                          </tr>
                          <tr valign="baseline">
                            <td align="right" nowrap class="aaaa">ContactEmail:</td>
                            <td><asp:textbox id="ContactEmail" TextMode="SingleLine" Columns="32" runat="server" />                      
                            </td>
                          </tr>
                          <tr valign="baseline">
                            <td nowrap align="right">&nbsp;</td>
                            <td><input name="approval" type="hidden" id="approval" value="0" /></td>
                          </tr>
                          <tr valign="baseline">
                            <td nowrap align="right">&nbsp;</td>
                            <td><input type="submit" OnClick="EmailDataGrid" value="Insert record"></td>
                          </tr>
                        </table>
                        <input type="hidden" name="MM_insert" value="form1">
                        <input name="submitted" type="hidden" id="submitted" value="<%=now%>" />
                      </form>
0
AGBrownCommented:
Possibly - it looks like you are working in Dreamweaver though - is that right? I don't have Dreamweaver set up to test with, so we might struggle a little.

Second question, did you put this in, and do you have a method called EmailDataGrid somewhere?
    <input type="submit" OnClick="EmailDataGrid" value="Insert record">

Andy
0
gianitooAuthor Commented:
i tried this  but it did not send

  <script runat="server">
 Sub EmailDataGrid(sender as Object, e as EventArgs)


        'System.Web.Mail.MailMessage Class
        Dim message As MailMessage = New MailMessage()

        message.From = "giani@indianayouthsoccer.org"
        message.To = "giani@indianayouthsoccer.org"
        message.Subject = "new job for approval"
        message.Body = "approve it or u will die"

        '------------------------------------------
        ' Also, if you are going to 'hard-code' the
        ' message text, use ControlChars.NewLine
        ' to create a new line (paragraph) in your
        ' mail message.
        '------------------------------------------

        'System.Web.Mail.SmtpMail Class
        SmtpMail.Send(message)

     

    End Sub </script>
0
AGBrownCommented:
Well, that's pretty close, but you need to specify an SMTP server in that code just before the SmtpMail.Send(message) line:

SmtpMail.SmtpServer = "enter mail server ip here";

Do you have an SMTP server to use?
0
gianitooAuthor Commented:
yes
0
gianitooAuthor Commented:
192.168.111.2    is the server address
0
AGBrownCommented:
well, I would try wacking that into the line I posted so that you have:

SmtpMail.SmtpServer = "x.x.x.x";
SmtpMail.Send(message);

However, I would set up a test page to test this so that you can be sure that the mail server send it working independently of this, more complex, page.
0
gianitooAuthor Commented:
why do we need "; "  at the end
0
gianitooAuthor Commented:
i tried this and it did not send   also no errors

  <script runat="server">
 Sub EmailDataGrid(sender as Object, e as EventArgs)


        'System.Web.Mail.MailMessage Class
        Dim message As MailMessage = New MailMessage()

        message.From = "giani@indianayouthsoccer.org"
        message.To = "giani@indianayouthsoccer.org"
        message.Subject = "new job for approval"
        message.Body = "approve it or u will die"

        '------------------------------------------
        ' Also, if you are going to 'hard-code' the
        ' message text, use ControlChars.NewLine
        ' to create a new line (paragraph) in your
        ' mail message.
        '------------------------------------------

        'System.Web.Mail.SmtpMail Class
SmtpMail.SmtpServer = "192.168.11.2"
        SmtpMail.Send(message)

     

    End Sub </script>
0
AGBrownCommented:
Sorry about the ; - I forgot you were in VB and slipped back into C#.

Well, this is the code that you will need to send email through an SMTP server. There is nothing wrote with the code as you have it (you could try setting the objMail.BodyFormat = MailFormat.Text but I don't think that will make much difference), which suggests that either the code is not firing, or that the smtp server is not accepting your send. If you could include the line

Me.Label1.Text = DateTime.Now.ToLongTimeString()

at the bottom of your code (you will need to add a label called Label1 to your page) you will know that the method has fired, in which case it will just be a communication problem with your smtp server.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.