Click here to Skip to main content
16,009,112 members
Home / Discussions / C#
   

C#

 
AnswerRe: Mouse cursor modification by getting data from web browser object Pin
Piccadilly Yum Yum25-Feb-11 3:10
Piccadilly Yum Yum25-Feb-11 3:10 
GeneralRe: Mouse cursor modification by getting data from web browser object Pin
HalliHaida27-Feb-11 17:16
HalliHaida27-Feb-11 17:16 
AnswerRe: Mouse cursor modification by getting data from web browser object Pin
Espen Harlinn25-Feb-11 4:13
professionalEspen Harlinn25-Feb-11 4:13 
Questioncreate an email application for own website Pin
gskumbhar24-Feb-11 22:49
gskumbhar24-Feb-11 22:49 
AnswerRe: create an email application for own website Pin
OriginalGriff24-Feb-11 22:58
mveOriginalGriff24-Feb-11 22:58 
GeneralRe: create an email application for own website Pin
Pravin Patil, Mumbai24-Feb-11 23:57
Pravin Patil, Mumbai24-Feb-11 23:57 
AnswerRe: create an email application for own website Pin
Pete O'Hanlon24-Feb-11 23:50
mvePete O'Hanlon24-Feb-11 23:50 
AnswerRe: create an email application for own website Pin
Dalek Dave25-Feb-11 0:00
professionalDalek Dave25-Feb-11 0:00 
Here is a VB.Net version I wrote some time ago, you can easily convert to c#.

Imports System
Imports System.Net
Imports System.Net.Mail
Imports System.Net.Mail.MailMessage
Imports System.Net.Mail.SmtpClient


Partial Class contacts

    Inherits System.Web.UI.Page

    Protected Sub Menu1_MenuItemClick(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.MenuEventArgs) Handles Menu1.MenuItemClick

    End Sub

    Protected Sub ContactName_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ContactName.TextChanged

    End Sub

    Protected Sub ContactAddress_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ContactAddress.TextChanged

    End Sub

    Protected Sub RadioButtonList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadioButtonList1.SelectedIndexChanged

    End Sub

    Protected Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

    End Sub

    Public Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim strName As String
        Dim strAddress As String
        Dim strMessage As String
        Dim strType As String
        Dim strSendTo As String
        Dim strSendFrom As String = "website@address.com"
        Dim CompleteMessage As String

        strName = ContactName.Text()
        strAddress = ContactAddress.Text()
        strMessage = TextBox1.Text()
        strType = RadioButtonList1.SelectedValue

        Select Case strType
            Case "sales"
                strSendTo = "Person1@address.com"
            Case "contractors"
                strSendTo = "Person2@Address.com"
            Case "general"
                strSendTo = "Person3@Address.com"
            Case Else
                strSendTo = "Person4@Address.com"
        End Select
        CompleteMessage = "Message From Website " & vbNewLine & strSendFrom & vbNewLine & strSendTo _
        & vbNewLine & vbNewLine & strType & vbNewLine & strMessage


        Dim mailClient As New SmtpClient()
        Dim Message As New MailMessage()
        Dim ToEmail As New MailAddress("Person1@address.com", "")
        Dim FromEmail As New MailAddress(strSendFrom, "")
        'String builder is used for performance reasons whil appending strings
        Dim messageBody As New System.Text.StringBuilder()
        messageBody.Append("Message Received From Website")
        messageBody.AppendLine()
        messageBody.Append(strType)
        messageBody.AppendLine()
        messageBody.Append(strSendFrom)
        messageBody.AppendLine()
        messageBody.Append(strSendTo)
        messageBody.AppendLine()
        messageBody.Append(strMessage)

        Message.Body = HttpUtility.HtmlDecode(messageBody.ToString)
        Message.Subject = strType
        'Message is sent in html format
        Message.IsBodyHtml = True
        Message.To.Add(ToEmail)
        Message.From = FromEmail
        Try
            mailClient.Send(Message)
        Catch ex As Exception

        End Try

    End Sub
    
End Class



You call it in the ASP page with something like this:

            </td>
            <td colspan="2" bgcolor="#CCFFCC">
                
                We are happy to hear from you on any matter, so please feel free to make 
                any comments or ask any questions using this form.<br />
                <br />
&nbsp;&nbsp;&nbsp;&nbsp;
                <asp:TextBox ID="ContactName" runat="server" Width="300px">Your Name</asp:TextBox>
&nbsp;&nbsp;&nbsp;&nbsp;
                <asp:TextBox ID="ContactAddress" runat="server" Width="300px">Email Address</asp:TextBox>
                <br />
                <br />
                Please indicate what type of contact:<br />
                <asp:RadioButtonList ID="RadioButtonList1" runat="server" Width="237px">
                    <asp:ListItem Value="sales">Sales Enquiry</asp:ListItem>
                    <asp:ListItem Value="contractors">Contractors Enquiry</asp:ListItem>
                    <asp:ListItem Value="general">General Enquiry</asp:ListItem>
                    <asp:ListItem Value="other">Other</asp:ListItem>
                </asp:RadioButtonList>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <asp:TextBox ID="TextBox1" runat="server" Height="130px" TextMode="MultiLine" 
                    Width="618px"></asp:TextBox>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <asp:Button ID="Button1" runat="server" Height="36px" Text="Send" 
                    Width="102px" />
                
                </td>

------------------------------------

I will never again mention that I was the poster of the One Millionth Lounge Post, nor that it was complete drivel. Dalek Dave

CCC Link[^]
Trolls[^]

GeneralRe: create an email application for own website Pin
Pravin Patil, Mumbai25-Feb-11 3:15
Pravin Patil, Mumbai25-Feb-11 3:15 
GeneralRe: create an email application for own website Pin
Dalek Dave25-Feb-11 5:58
professionalDalek Dave25-Feb-11 5:58 
GeneralRe: create an email application for own website Pin
Ali Al Omairi(Abu AlHassan)25-Feb-11 8:53
professionalAli Al Omairi(Abu AlHassan)25-Feb-11 8:53 
AnswerRe: create an email application for own website Pin
Abhinav S25-Feb-11 3:21
Abhinav S25-Feb-11 3:21 
AnswerRe: create an email application for own website Pin
RaviRanjanKr28-Feb-11 2:34
professionalRaviRanjanKr28-Feb-11 2:34 
QuestionObject reference not set to an instance of an object. Pin
Pierre besquent24-Feb-11 21:55
Pierre besquent24-Feb-11 21:55 
AnswerRe: Object reference not set to an instance of an object. Pin
OriginalGriff24-Feb-11 22:32
mveOriginalGriff24-Feb-11 22:32 
GeneralRe: Object reference not set to an instance of an object. Pin
Pierre besquent24-Feb-11 22:39
Pierre besquent24-Feb-11 22:39 
GeneralRe: Object reference not set to an instance of an object. Pin
OriginalGriff24-Feb-11 22:44
mveOriginalGriff24-Feb-11 22:44 
GeneralRe: Object reference not set to an instance of an object. Pin
Pierre besquent24-Feb-11 22:51
Pierre besquent24-Feb-11 22:51 
GeneralRe: Object reference not set to an instance of an object. Pin
OriginalGriff24-Feb-11 22:58
mveOriginalGriff24-Feb-11 22:58 
AnswerRe: Object reference not set to an instance of an object. Pin
_Erik_24-Feb-11 22:36
_Erik_24-Feb-11 22:36 
GeneralRe: Object reference not set to an instance of an object. Pin
Pierre besquent24-Feb-11 22:50
Pierre besquent24-Feb-11 22:50 
GeneralRe: Object reference not set to an instance of an object. Pin
_Erik_24-Feb-11 22:59
_Erik_24-Feb-11 22:59 
AnswerRe: Object reference not set to an instance of an object. Pin
Abhinav S25-Feb-11 3:24
Abhinav S25-Feb-11 3:24 
AnswerRe: Object reference not set to an instance of an object. Pin
Eddy Vluggen25-Feb-11 10:20
professionalEddy Vluggen25-Feb-11 10:20 
AnswerRe: Object reference not set to an instance of an object. Pin
PrimeCoder25-Feb-11 23:01
PrimeCoder25-Feb-11 23:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.