Solved

Send Email Confirmation to User

Posted on 2014-02-24
3
316 Views
Last Modified: 2014-02-26
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

0
Comment
Question by:misnstt
  • 2
3 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 39885002
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.
0
 

Author Comment

by:misnstt
ID: 39885254
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.
0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
ID: 39885334
Basically you need two things; a MailMessage object:
MailMessage message = new MailMessage();

// define sender address
message.From = new MailAddress("sender@somewhere.com");
 
// define recipient address
message.To.Add(new MailAddress("recipient1@somewhereelse.com"));

// specify message subject and body
message.Subject = "This is my subject";
message.Body = "This is the content";

Open in new window

Which you then send using a SmtpClient object:
SmtpClient client = new SmtpClient();
client.Send(message);

Open in new window

The configuration for the SmtpClient can be done in web.config, under the <system.net> element:
  <system.net>
    <mailSettings>
      <smtp from="sender@somewhere.com">
        <network host="smtpserver1" port="25" userName="username" password="secret" defaultCredentials="true" />
      </smtp>
    </mailSettings>
  </system.net>

Open in new window

0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
This article discusses how to create an extensible mechanism for linked drop downs.
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now