-
Oct 11th, 2013, 02:50 PM
#1
Thread Starter
Hyperactive Member
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("\"",""") '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.
-
Oct 11th, 2013, 08:29 PM
#2
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.
-
Oct 12th, 2013, 01:06 AM
#3
Addicted Member
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 |||
-
Oct 12th, 2013, 01:16 AM
#4
Re: Emailing (SMTP) and including a reply link (?)
Originally Posted by jalexander
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.
-
Oct 12th, 2013, 06:50 AM
#5
Re: Emailing (SMTP) and including a reply link (?)
Originally Posted by jmcilhinney
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:
Imports System.Net.Mail Imports System.Net Imports System.Text Public Class Form1 Private Sub MailTo(ByVal userName As String, ByVal password As String) Dim sb As New StringBuilder Dim body As String = String.Format("<a href=""mailto:sam@?Subject={0}"">{1}</a>", "mailto subject", "mailto body with invalid chars %£^&^#?.,|45432653%* &^(*&P{@~P{@") sb.AppendLine("<!DOCTYPE html>") sb.AppendLine("<html>") sb.AppendLine(" <body>") sb.AppendLine(" <p>") sb.AppendLine(body) sb.AppendLine(" </p>") sb.AppendLine(" </body>") sb.AppendLine("</html>") Dim mail As New MailMessage With { .From = New MailAddress("mail@.com"), .Subject = "Html Body", .Body = sb.ToString, .IsBodyHtml = True } Dim smtp As New SmtpClient With { .Credentials = New NetworkCredential(userName, password), .Port = 587, .Host = "smtp.gmail.com", .EnableSsl = True } mail.To.Add("") smtp.Send(mail) End Sub 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.
Last edited by ident; Sep 15th, 2022 at 09:34 AM.
-
Oct 12th, 2013, 07:10 AM
#6
Re: Emailing (SMTP) and including a reply link (?)
-
Oct 12th, 2013, 06:02 PM
#7
Thread Starter
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|