Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Send Email Confirmation to User

Posted on 2014-02-24
3
Medium Priority
?
340 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)

719 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