Link to home
Start Free TrialLog in
Avatar of misnstt
misnstt

asked on

Send Email Confirmation to User

Hello I have a Dialog on my site where users can select on a persons profile and and send that person a email.  There is no problem with the profile owner receiving the message however I want to expand it and the profile owner should receive a email to advise that they have received a new message.  The profile page includes the profile owner email address and UserID.

I am not sure what I need to do to accomplish this.



Protected Sub Button1_Click(sender As Object, e As EventArgs)
        ' Insert a new record 
        Dim connectionString As String = ConfigurationManager.ConnectionStrings("dbMyCMSConnectionString").ConnectionString
        Dim insertSql As String = "INSERT INTO [Messaging] ([UserId], [emailaddress], [message], [howmanyguest], [servicetype], [name], [DateString]) VALUES (@UserId, @emailaddress, @message, @howmanyguest, @servicetype, @name, @DateString)"
        Using myConnection As New SqlConnection(connectionString)
            myConnection.Open()
            Dim myCommand As New SqlCommand(insertSql, myConnection)
            myCommand.Parameters.AddWithValue("UserId", UserId.Text.Trim())
            myCommand.Parameters.AddWithValue("@emailaddress", emailaddress.Text.Trim())
            myCommand.Parameters.AddWithValue("@message", message.Text.Trim())
            myCommand.Parameters.AddWithValue("@howmanyguest", howmanyguest.Text.Trim())
            myCommand.Parameters.AddWithValue("@servicetype", servicetype.Text.Trim())
            myCommand.Parameters.AddWithValue("@name", name.Text.Trim())
            myCommand.Parameters.AddWithValue("@DateString", DateString.Text.Trim())
            myCommand.ExecuteNonQuery()
            myConnection.Close()

            emailaddress.Text = String.Empty
            howmanyguest.Text = String.Empty
            servicetype.Text = String.Empty
            message.Text = String.Empty
            name.Text = String.Empty

            Dim sReturn As String = "Your Message Was Sent"

            Response.Write((Convert.ToString("<script>alert('") & sReturn) + "');</script>")

        End Using

    End Sub

Open in new window

Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

Well the first thing you need is a mail server. Do you have one available, do you know the details for it (servername, port, security credentials if needed)?

Secondly you'll need to decide how to send mail. You can either do it direct from code using classes in the System.Net.Mail namespace, or you can send directly from a stored procedure in your database.
Avatar of misnstt
misnstt

ASKER

Hello and thanks for your response.  Yes I have a mail server and I know all the details.  I currently use it when people send me emails on the site.  However my security credentials (email address and password). are set in the code behind on that one.  what im looking for now is for the user to send a message to the person in the profile and the person in the profile will receive a email notification stating that they should login to the site and view their email.
I have the profile persons email address already in the system I just dont know how the proper method to code this.

I would rather use classes in the System.Net.Mail. for this.
ASKER CERTIFIED SOLUTION
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial