locked
sending email to new user after user created. RRS feed

  • Question

  • User627859671 posted

    I have a register user window with first name last name user name and email, then i have sewcond database table called user_profile with user id last name and first name. Everything works create user update the first name and last name in the user_prfile table and send email to new user with welcome message and their password but i can not figure it out how to get the first name and last name in the message body with their user name and password. i have the mail definition bodt text file. Thank you for all the help.

    Monday, April 7, 2014 7:32 AM

All replies

  • User-1618234021 posted

    Its pretty simple. You can set the Body of the MailMessage object to any valid string. See the following link:

    http://asp.net-tutorials.com/misc/sending-mails/

    Monday, April 7, 2014 9:10 AM
  • User-734925760 posted

    Hi,

    According to your description, if you want to get the email message in the code behind, I think we can seesion the message as we create the email. Then we can use them directly via adeelehsan's reply.

    If you want to open the mail from outlook, I think you should get all the content of the email body, then you can loop the content tp get the value you want.

    There is a similar thread, please refer to the link below:

    http://social.msdn.microsoft.com/Forums/office/en-US/5fbc9aa0-0f00-4062-a74b-7610ea4bd507/get-data-from-email-body

    Hope it's useful for you.

    Best Regards,

    Michelle Ge

    Wednesday, April 9, 2014 4:57 AM
  • User627859671 posted

    Thank you for your post.

    In the create user wizard i have first name, last name user name and email then email body text file i have <%username%> <%password%> I like to add the first name and last name in the email but they are in the diffrent table. How can i do that.

    Imports System.Data.SqlClient
    
    Partial Class Account_register2
        Inherits System.Web.UI.Page
        Protected Sub CreateUserWizard1_CreatedUser(ByVal sender As Object, ByVal e As EventArgs) Handles CreateUserWizard1.CreatedUser, CreateUserWizard1.DataBinding
            ' Get the UserId of the just-added user
            Dim newUser As MembershipUser = Membership.GetUser(CreateUserWizard1.UserName)
            Dim newUserId As Guid = DirectCast(newUser.ProviderUserKey, Guid)
    
            'Get Profile Data Entered by user in CUW control
    
            Dim FName As String = DirectCast(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("FName"), TextBox).Text
            Dim LName As String = DirectCast(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("LName"), TextBox).Text
    
            ' Insert a new record into User_Profile
    
            ' Get your Connection String from the web.config. MembershipConnectionString is the name I have in my web.config
            Dim connectionString As String = ConfigurationManager.ConnectionStrings("ApplicationServices").ConnectionString
    
            Dim insertSql As String = "INSERT INTO User_Profile(UserId,FName, LName) VALUES(@UserId, @FName, @LName)"
            Using myConnection As New SqlConnection(connectionString)
                myConnection.Open()
                Dim myCommand As New SqlCommand(insertSql, myConnection)
                myCommand.Parameters.AddWithValue("@UserId", newUserId)
                myCommand.Parameters.AddWithValue("@FName", FName)
                myCommand.Parameters.AddWithValue("@LName", LName)
    
                myCommand.ExecuteNonQuery()
                myConnection.Close()
            End Using
        End Sub
    End Class
    

    <%@ Page Title="" Language="VB" MasterPageFile="~/Site.master" AutoEventWireup="false" CodeFile="register2.aspx.vb" Inherits="Account_register2" %>
    
    <asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server"> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">     <asp:CreateUserWizard ID="CreateUserWizard1" runat="server"     AutoGeneratePassword="True" LoginCreatedUser="False"         Width="235px">     <MailDefinition From="admin@xxxxxxx.net" IsBodyHtml="True"         Subject="your new account" BodyFileName="~/Account/Newaccount.txt" >     </MailDefinition>     <WizardSteps>         <asp:CreateUserWizardStep runat="server" >             <ContentTemplate>                 <table>                     <tr>                         <td align="center" colspan="2">                             Sign Up for Your New Account</td>                     </tr>                     <tr>
    
    <td align="right">
    
    <asp:Label ID="FirstNameLabel" runat="server" AssociatedControlID="FName">First Name:</asp:Label></td>
    
    <td>
    
    <asp:TextBox ID="FName" runat="server"></asp:TextBox>
    
    <asp:RequiredFieldValidator ID="FNameValidator" runat="server" ControlToValidate="FName"
    
    ErrorMessage="First Name is required." ToolTip="First Name is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
    
    </td> <tr>
    
    <td align="right">
    
    <asp:Label ID="LastNameLabel" runat="server" AssociatedControlID="LName">Last Name:</asp:Label></td>
    
    <td>
    
    <asp:TextBox ID="LName" runat="server"></asp:TextBox>
    
    <asp:RequiredFieldValidator ID="LNameValidator" runat="server" ControlToValidate="LName"
    
    ErrorMessage="Last Name is required." ToolTip="Last Name is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
    
    </td>
    
    </tr> </tr>                     <tr>                         <td align="right">                             <asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">User Name:</asp:Label>                         </td>                         <td>                             <asp:TextBox ID="UserName" runat="server"></asp:TextBox>                             <asp:RequiredFieldValidator ID="UserNameRequired" runat="server"                                 ControlToValidate="UserName" ErrorMessage="User Name is required."                                 ToolTip="User Name is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>                         </td>                     </tr>                     <tr>                         <td align="right">                             <asp:Label ID="EmailLabel" runat="server" AssociatedControlID="Email">E-mail:</asp:Label>                         </td>                         <td>                             <asp:TextBox ID="Email" runat="server"></asp:TextBox>                             <asp:RequiredFieldValidator ID="EmailRequired" runat="server"                                 ControlToValidate="Email" ErrorMessage="E-mail is required."                                 ToolTip="E-mail is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>                         </td>                     </tr>
    
                        <tr>                         <td align="center" colspan="2" style="color:Red;">                             <asp:Literal ID="ErrorMessage" runat="server" EnableViewState="False"></asp:Literal>                         </td>                     </tr>                 </table>             </ContentTemplate>         </asp:CreateUserWizardStep>         <asp:CompleteWizardStep runat="server" >             <ContentTemplate>                 <table style="font-size:100%;width:235px;">                     <tr>                         <td align="center" colspan="2">                             Complete</td>                     </tr>                     <tr>                         <td>                             Your account has been successfully created.</td>                     </tr>                     <tr>                         <td align="right" colspan="2">                             <asp:Button ID="ContinueButton" runat="server" CausesValidation="False"                                 CommandName="Continue" Text="Continue" ValidationGroup="CreateUserWizard1" />                         </td>                     </tr>                 </table>             </ContentTemplate>         </asp:CompleteWizardStep>     </WizardSteps> </asp:CreateUserWizard>
    
            </asp:Content>
    
    
    
    

    Saturday, April 12, 2014 10:34 PM