Solved

Send Email Confirmation to User

Posted on 2014-02-24
3
326 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

856 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