Results 1 to 7 of 7

Thread: Emailing (SMTP) and including a reply link (?)

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2008
    Location
    PA
    Posts
    365

    Emailing (SMTP) and including a reply link (?)

    First thing is first. I have completed the emailing portion successfully. I am trying to format it a little better and include a link inside the body (basically a mailto: link). The email is already set to .IsBodyHtml.

    So:
    Code:
    'Using a Stringbuilder
    'Add text
    'Add text & "<a href = \"mailto:" & EmailAddress & ">" & EmailAddress & "</a>"
    'Add text
    ...
    That's simple enough. But, I wanted to try to make the entire e-mail be included when the mailto: link was clicked. Thus, acting like a sort of fwd/reply. So, I attempted to include the ?body= part onto the mailto: link.
    Code:
    'Using a Stringbuilder
    'Add text
    'Add text & "<a href = \"mailto:" & EmailAddress & "?body=~~BODYHERE~~>" & EmailAddress & "</a>"
    'Add text
    ...
    And then attempted to replace ~~BODYHERE~~ with the entirety of the StringBuilder
    Code:
    'All variables used are already declared at this point
    Dim body As String = sb.ToString().Replace("?body=~~BODYHERE~~","") 'make sure we don't keep replacing infinitely
    body = body.Replace("\"","&#34;") 'replace " with ascii version
    message.Body = sb.ToString().Replace("~~BODYHERE~~",body) 'replace the body part of the mailto: link in the original stringbuilder only
    smtp.Send(message)
    The result:
    A blue underlined link in outlook.com but goes nowhere and doesn't display a url to go to at the bottom of the browser. In gmail, the link isn't blue or underlined, it's completely un-clickable...

    I'm going to assume that my approach isn't very effective, but it would be a huge improvement to include the e-mail body in the new e-mail when users click the e-mail address in the body of the original.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,296

    Re: Emailing (SMTP) and including a reply link (?)

    You are including that text in a URL so you can only use characters that are allowed in a URL. Presumably your text has at least spaces in it, but possibly other invalid characters too. You should probably look at using the HttpUtility.UrlEncode method to create text that is allowed in a URL.

  3. #3
    Addicted Member jalexander's Avatar
    Join Date
    Jan 2011
    Location
    Memphis, TN
    Posts
    160

    Re: Emailing (SMTP) and including a reply link (?)

    Hi,
    I can't help with your question but I just wanted to point out...
    That if this is for a commercial application... a lot of people have no default "mailto:" program installed on their computer. Most people don't use things like Microsoft outlook anymore. So it's really not a practical way of doing things...unless you're just dealing with a small control group / i.e. small company intranet, or just for personal use.
    dim jenn as geek = true
    Learning ~ Visual Basic 2010 ~ in free time between college/work -
    currently looking for a 'programming buddy' / 'coder friend' / and or 'mentor'. p.m. me if you
    have ANY free time AT ALL I'm like 33% of a novice level ~ willing 2 listen/learn +
    i am totally super motivated & promise to make an effffin amazing protege!!! #swag

    | -_-_- -_-_- |
    ...W.T..F!?.....
    ||| Matter on the atomic/quantum level isn't solid or even matter at all. It can also exist in at least 2 places simultaneously (demonstrated in lab). It's position can only be established when it's actually observed. If we turn our back on it... it goes back to a wave form. History show's that every previous generation (since the beginning of time) got almost everything wrong. Then it might very well stand to reason that up is down & right can be wrong. Admit it.. our combined perception of reality is just that, we know absolutely nothing of actual reality & to think we do is simply subscribing to a "ignorance is bliss" mantra |||

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,296

    Re: Emailing (SMTP) and including a reply link (?)

    Quote Originally Posted by jalexander View Post
    Hi,
    I can't help with your question but I just wanted to point out...
    That if this is for a commercial application... a lot of people have no default "mailto:" program installed on their computer. Most people don't use things like Microsoft outlook anymore. So it's really not a practical way of doing things...unless you're just dealing with a small control group / i.e. small company intranet, or just for personal use.
    Is that a reason not to include the link? Those people who use web mail can simply replay as normal and those using a dedicated application can use the link. It's not like including the link is stopping anyone doing anything.

  5. #5
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,398

    Re: Emailing (SMTP) and including a reply link (?)

    Quote Originally Posted by jmcilhinney View Post
    You are including that text in a URL so you can only use characters that are allowed in a URL. Presumably your text has at least spaces in it, but possibly other invalid characters too. You should probably look at using the HttpUtility.UrlEncode method to create text that is allowed in a URL.
    At first i was inclined to agree, but if we encode the url then the displayed body will also be displayed encoded at the users end. It's the actual HTML thats incorrect.

    vb Code:
    1. Imports System.Net.Mail
    2. Imports System.Net
    3. Imports System.Text
    4.  
    5. Public Class Form1
    6.  
    7.     Private Sub MailTo(ByVal userName As String, ByVal password As String)
    8.  
    9.         Dim sb As New StringBuilder
    10.         Dim body As String = String.Format("<a href=""mailto:sam@?Subject={0}"">{1}</a>",
    11.                                            "mailto subject",
    12.                                            "mailto body with invalid chars %£^&^#?.,|45432653%* &^(*&P{@~P{@")
    13.  
    14.         sb.AppendLine("<!DOCTYPE html>")
    15.         sb.AppendLine("<html>")
    16.         sb.AppendLine("    <body>")
    17.         sb.AppendLine("        <p>")
    18.         sb.AppendLine(body)
    19.         sb.AppendLine("        </p>")
    20.         sb.AppendLine("    </body>")
    21.         sb.AppendLine("</html>")
    22.  
    23.         Dim mail As New MailMessage With
    24.             {
    25.             .From = New MailAddress("mail@.com"),
    26.             .Subject = "Html Body",
    27.             .Body = sb.ToString,
    28.         .IsBodyHtml = True
    29.             }
    30.  
    31.         Dim smtp As New SmtpClient With
    32.             {
    33.             .Credentials = New NetworkCredential(userName, password),
    34.             .Port = 587,
    35.             .Host = "smtp.gmail.com",
    36.             .EnableSsl = True
    37.             }
    38.  
    39.         mail.To.Add("")
    40.  
    41.         smtp.Send(mail)
    42.     End Sub
    43. End Class

    ah thinking about it i assume you mean the body in the actual mailto link like i included a subject, but then still it will be displayed encoded.

  6. #6

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2008
    Location
    PA
    Posts
    365

    Re: Emailing (SMTP) and including a reply link (?)

    Hey guys!

    Thanks for all the help and suggestions.

    However, after the headaches of it all since attempting it, we decided to scrap the idea of the mailto: link. We are just manipulating the sending address to be that of what we had in the mailto: link. We decided that's the easiest way since our company was sending e-mails on behalf of others and we didn't need the responses, the others did. Our initial testing was successful!

    I appreciate the suggestions here as well, but I'm not that fluent in html code.

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