Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Send Email Confirmation to User

Posted on 2014-02-24
3
Medium Priority
?
345 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 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

963 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