CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Mar 2002
    Location
    Colorado
    Posts
    105

    Hyperlink in text string

    Hello,

    Is there a way to include a hyperlink inside a string? I am using SMTP to send a verification email, and I would like to inlcude a hyperlink to the website login, as well as a link to the admin email. I was able to get this working, but the entire path show up for the hyperlink, and "mailto:" is including at the beginning of the email link. For formatting purposes I would like this to be setup similar to a standard A HREF hyperlink tag. Here is the code i am working with. Thanks for any help on this!

    Code:
        Private Sub SendEmailNotification(ByVal Message As String, ByVal Question As String, ByVal OptionName As String, ByVal Rating As String)
    
                Dim mailMsg As New MailMessage("[email protected]", "[email protected]")
    
                With mailMsg
                    .Subject = "Moderation Required!"
                    .Body = UserInfo.DisplayName & " has modified comments related to """ & Question & """. Please Log into ""MyBold"" to review." & vbCrLf & vbCrLf _
                     & "       User: " & UserInfo.DisplayName & vbCrLf _
                     & "   Question: " & Question & vbCrLf _
                     & "Option Name: " & OptionName & vbCrLf _
                     & "     Rating: " & Rating & vbCrLf _
                     & "    Comment: " & Message & vbCrLf _
                     & "  Date/Time: " & Now() & vbCrLf & vbCrLf _
                     & "Login to http://www.mywebsite.com/bt2/Home/tabid/36/ctl/Login/Default.aspx?returnurl=%2fbt2%2fHome%2ftabid%2f36%2fDefault.aspx to moderate user requests." & vbCrLf _"
                     & "Admin:" & vbCrLf _
                     & "mailto:" & mailMsg.From.Address
    
                End With
    
                Try
                    Dim emailClient As New SmtpClient("dom-02.boldgroup.int", 25)
                    emailClient.Send(mailMsg)
                Catch exp As Exception
                    lblUserMessage.Text = exp.ToString()
                End Try
    
            End Sub

  2. #2
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    1,080

    Re: Hyperlink in text string

    Your MailMessage needs to be in HTML format first, then you just make the body a string containing HTML code, including an HREF tag.
    Tutorials: Home & Learn | Start VB.NET | Learn VB.NET | C# Station | GotDotNet | Games in VB.NET 101 Samples: 2002 | 2003 | 2005 | More .NET 2.0 (VB.NET, C#) Articles: VB.NET | C# | ASP.NET | MoreFree Components: WFC | XPCC | ElementsEx | VBPP | Mentalis | ADO.NET/MySQL | VisualStyles | Charting (NPlot, ZedGraph) | iTextSharp (PDF) | SDF (CF) ● Free Literature: VB 2005 (eBook) | VB6 to VB.NET (eBook) | MSDN Magazine (CHM format) ● Bookmarks: MSDN | WinForms .NET | ASP.NET | WinForms FAQ | WebForms FAQ | GotDotNet | Code Project | DevBuzz (CF) ● Code Converter: C#/VB.NET | VB.NET/C# | VS 2005 add-in

  3. #3
    Join Date
    Jan 2003
    Location
    7,107 Islands
    Posts
    2,487

    Re: Hyperlink in text string

    here is a sample code

    Code:
          Dim m As New System.Web.Mail.MailMessage
          Dim sm As System.Web.Mail.SmtpMail
    
          m.BodyFormat = Web.Mail.MailFormat.Html
          m.To = "[email protected]"
          m.From = "[email protected]"
          m.Subject = "test"
          m.Body = "<html><body>" & _
                   "<p />" & _
                   "Please click <a href=""http://domain.com/mysite"">here</a> to login." & _
                   "<p />" & _
                   "Please click <a href=""mailto:[email protected]"">here</a> to mail me." & _
                   "</body></html>"
    
          sm.SmtpServer = "<your mail server here>"
          sm.Send(m)
    Busy

  4. #4
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    1,080

    Re: Hyperlink in text string

    Quote Originally Posted by Thread1
    here is a sample code

    Code:
          Dim m As New System.Web.Mail.MailMessage
          Dim sm As System.Web.Mail.SmtpMail
    
          m.BodyFormat = Web.Mail.MailFormat.Html
          m.To = "[email protected]"
          m.From = "[email protected]"
          m.Subject = "test"
          m.Body = "<html><body>" & _
                   "<p />" & _
                   "Please click <a href=""http://domain.com/mysite"">here</a> to login." & _
                   "<p />" & _
                   "Please click <a href=""mailto:[email protected]"">here</a> to mail me." & _
                   "</body></html>"
    
          sm.SmtpServer = "<your mail server here>"
          sm.Send(m)
    The OP is using System.Net.Mail (.Net 2.0+), not System.Web.Mail (.NET 1.x).
    Tutorials: Home & Learn | Start VB.NET | Learn VB.NET | C# Station | GotDotNet | Games in VB.NET 101 Samples: 2002 | 2003 | 2005 | More .NET 2.0 (VB.NET, C#) Articles: VB.NET | C# | ASP.NET | MoreFree Components: WFC | XPCC | ElementsEx | VBPP | Mentalis | ADO.NET/MySQL | VisualStyles | Charting (NPlot, ZedGraph) | iTextSharp (PDF) | SDF (CF) ● Free Literature: VB 2005 (eBook) | VB6 to VB.NET (eBook) | MSDN Magazine (CHM format) ● Bookmarks: MSDN | WinForms .NET | ASP.NET | WinForms FAQ | WebForms FAQ | GotDotNet | Code Project | DevBuzz (CF) ● Code Converter: C#/VB.NET | VB.NET/C# | VS 2005 add-in

  5. #5
    Join Date
    Jan 2003
    Location
    7,107 Islands
    Posts
    2,487

    Re: Hyperlink in text string

    ^ nice catch
    Busy

  6. #6
    Join Date
    Mar 2002
    Location
    Colorado
    Posts
    105

    Re: Hyperlink in text string

    Many Thanks! Its working now.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured