Can't send a mail with a 'protocol'-link :o(

Hi,

When I use System.Net.Mail.MailMessage to send a message with a protocol-link in the body-html like this...

<a href="myProtocol://test">Click me</a>

... all I recieve is this...

<a>Click me</a>

The href part is gone.

I don't know if it's dotnet or outlook that is removing the href part.

Here's my sample code:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim mail As New System.Net.Mail.MailMessage
Dim smtp As System.Net.Mail.SmtpClient = New System.Net.Mail.SmtpClient("my_smtp_server")
With mail
.From =
New System.Net.Mail.MailAddress('myemail@company.com')
.To.Add(
New System.Net.Mail.MailAddress('myemail@company.com'))
.Subject =
"Test"
.Body = BuildMail()
.IsBodyHtml =
True
End With
With smtp
.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials
.Send(mail)
End With
End Sub

Private Function BuildMail() As String
Dim sb As New System.Text.StringBuilder
sb.AppendLine(
"<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.0 Transitional//EN'>")
sb.AppendLine(
"<html>")
sb.AppendLine(
"<head>")
sb.AppendLine(
"<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>")
sb.AppendLine(
"<meta content='MSHTML 6.00.2900.2802' name='GENERATOR'>")
sb.AppendLine(
"</head>")
sb.AppendLine(
"<body>")
sb.AppendLine(
"<a href='myProtocol://test'>Click here</a>")
sb.AppendLine(
"</body>")
sb.AppendLine(
"</html>")
Return sb.ToString
End Function

How come that code removes the href part

Thank you in advance!!!!!!

Mojo



Answer this question

Can't send a mail with a 'protocol'-link :o(

  • Randy_TS

    Hi Mariya,

    I get the same result as you. So I guess, that it's not dotnet messing up my links.

    I've spoken with GFI (spam + anti virus vendor), they say it's not their products either ... hmmmm. I'm lost.

    But thank you so much for helping me out here!!!!!

    Kind regards,
    Mojo


  • Mike Whyte

    Hi Mariya,

    Thanks for helping me out here!!

    I did what you said, but I can't figure out how to read the tracelog. Can you help me and see if there's a problem here (I've blurred out the from at to sender adress):

    System.Net Information: 0 : [119632] Associating MailMessage#33163964 with Message#14421545
    System.Net Verbose: 0 : [119632] SmtpClient::.ctor(host=post.cybercity.dk)
    System.Net Information: 0 : [119632] Associating SmtpClient#35567111 with SmtpTransport#65066874
    System.Net Verbose: 0 : [119632] Exiting SmtpClient::.ctor() -> SmtpClient#35567111
    System.Net Verbose: 0 : [119632] SmtpClient#35567111::Send(MailMessage#33163964)
    System.Net Information: 0 : [119632] SmtpClient#35567111::Send(DeliveryMethod=Network)
    System.Net Information: 0 : [119632] Associating SmtpClient#35567111 with MailMessage#33163964
    System.Net Information: 0 : [119632] Associating SmtpTransport#65066874 with SmtpConnection#34160229
    System.Net Information: 0 : [119632] Associating SmtpConnection#34160229 with ServicePoint#63238509
    System.Net Information: 0 : [119632] Associating SmtpConnection#34160229 with SmtpPooledStream#11679222
    System.Net Information: 0 : [119632] HeaderCollection#35410979::Set(content-transfer-encoding=base64)
    System.Net Information: 0 : [119632] HeaderCollection#35410979::Set(content-transfer-encoding=quoted-printable)
    System.Net Information: 0 : [119632] Associating Message#14421545 with HeaderCollection#57416410
    System.Net Information: 0 : [119632] HeaderCollection#57416410::Set(mime-version=1.0)
    System.Net Information: 0 : [119632] HeaderCollection#57416410::Set(from=myFrom@company.com)
    System.Net Information: 0 : [119632] HeaderCollection#57416410::Remove(sender)
    System.Net Information: 0 : [119632] HeaderCollection#57416410::Set(to=myTo@company.com)
    System.Net Information: 0 : [119632] HeaderCollection#57416410::Set(date=2 Jun 2006 07:11:28 +0200)
    System.Net Information: 0 : [119632] HeaderCollection#57416410::Set(subject=Test)
    System.Net Information: 0 : [119632] HeaderCollection#57416410::Get(mime-version)
    System.Net Information: 0 : [119632] HeaderCollection#57416410::Get(from)
    System.Net Information: 0 : [119632] HeaderCollection#57416410::Get(to)
    System.Net Information: 0 : [119632] HeaderCollection#57416410::Get(date)
    System.Net Information: 0 : [119632] HeaderCollection#57416410::Get(subject)
    System.Net Information: 0 : [119632] HeaderCollection#35410979::Get(content-type)
    System.Net Information: 0 : [119632] HeaderCollection#35410979::Get(content-transfer-encoding)
    System.Net Information: 0 : [119632] HeaderCollection#35410979::Get(content-transfer-encoding)
    System.Net Information: 0 : [119632] HeaderCollection#35410979::Get(content-transfer-encoding)
    System.Net Information: 0 : [119632] HeaderCollection#35410979::Get(content-transfer-encoding)
    System.Net Information: 0 : [119632] HeaderCollection#35410979::Get(content-transfer-encoding)
    System.Net Verbose: 0 : [119632] Exiting SmtpClient#35567111::Send()

    Any idea

    Thanks a million!!

    Mojo


  • Gunter A.

    I forgot to mention...

    I've tried to use Outlook to send the link to myself, that worked perfectly, so I guess it must be a .net issue.

    Mojo


  • Andrija

    Mojo,

    I'll send you an e-mail with the full log I got and info and how to read it. Basically in your log you're missing the socket info. To get it you need to add this part to your config file as well

    <source name="System.Net.Sockets">
    <listeners>
    <add name="System.Net"/>
    </listeners>
    </source>

    From the results I got we send the link fine. It could be that your e-mail server is removing them


    Mariya


  • Hans Guan

    Mojo,

    I couldn't repro your issue: I send a message using SmtpClient using the exact same body and the whole link arrived as it was supposed to <a href='myProtocol://test'>Click here</a> It also showed on Outlook and Outlook express.

    You can use a Netmon sniff or get a System.Net trace log and see what gets sent. Instructions on how to get a trace.log are here

    http://blogs.msdn.com/dgorti/archive/2005/09/18/471003.aspx

    Let me know if this helped
    Mariya


  • GlennSmith

    Hello,

    for me it worked without the

    sb.AppendLine("<meta content='MSHTML 6.00.2900.2802' name='GENERATOR'>")

    hope this helps


  • Can't send a mail with a 'protocol'-link :o(