How to put a hyperlink into the email body using vb.net - vb.net

What im trying to do is add a hyperlink to the body of an email in vb.net. What im getting when i send the email is the link is text. Here is what I doing so far below. Any help would be very much appreciated.
'Accepts two parameters - the username and password for the email client
Dim credentials As New System.Net.NetworkCredential("test#test.net", "test")
smtpClient.Credentials = credentials
Dim body, link As String
link = "http://localhost:" & partUrl & "/test.aspx?autoNum=" & autoNum
body = "Test email." & "<br/><br/>"
body += link
Dim email As New MailMessage
email.From = New MailAddress("test#test.net")
email.Body = body
email.Subject = "test Change/Request Password"
email.To.Add(New MailAddress(toAddress))
smtpClient.Send(email)

You will need to enclose it in a tags.
link = "Click here"
And you need to set
email.IsBodyHtml = true

Try this:
link = "Link"
body = "Test email." & "<br/><br/>"
body += link
The idea (I can't test it now, sorry) is you have to add not the url itself, but the HTML code used to create link.
Remember to set mail body to html with email.IsBodyHtml = True

I believe you need to set
IsBodyHtml = True
Then you can use plain HTML in the body of the e-mail. It's still up to the mail client to display it correctly. I've had a few cases where valid HTML that looked create in my browser was messy in my e-mail.

You haven't identified the body as HTML.
Add:
email.IsBodyHtml = true

Related

Send newsletter HTML Email with pictures as body

I'm new to this group and i have one question. how can i attach pictures on the HTML newsletter that i have. when i send the newsletter everything goes well but the pictures are not showing on the email. please help. this is the code.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim Body As String = GetWebPageContent(Sender_email, Message)
Dim Mail As New MailMessage
Mail.Subject = "Test HTML"
Mail.To.Add(to_email)
Mail.From = New MailAddress(Sender_email)
Mail.Body = Body
Mail.IsBodyHtml = True
Mail.Priority = MailPriority.Normal
Dim SMTP As New SmtpClient(SMTP_Confg)
SMTP.EnableSsl = False
SMTP.Credentials = New System.Net.NetworkCredential(Sender_email, Password)
SMTP.Port = Port_Num
Try
SMTP.Send(Mail)
MsgBox("Successfully Sent!!!")
Catch ex As Exception
MessageBox.Show(" - your confermation email is not sent! " & vbNewLine & " Please contact your Administrator!")
End Try
End Sub
Private Function GetWebPageContent(ByVal recipient As String, ByVal customMsg As String) As String
Dim objStreamReader As New StreamReader("C:\Users\alex.GFH\Desktop\Email\beefree-s09uuvnlono.HTML")
'read html template file'
Dim bodyMsg As String = objStreamReader.ReadToEnd()
Return bodyMsg
End Function
It looks like you're copying the raw HTML from this file:
"C:\Users\alex.GFH\Desktop\Email\beefree-s09uuvnlono.HTML"
As the message body of your email.
My psychic powers tell me that you've got <img> tags inside your HTML that are pointing to relative locations. e.g. <img src="picture.jpg"/>. As such when the HTML email is opened in someone else's browser or mail app, the renderer has no idea where to fetch "picture.jpg" from.
And even if it did have the full URL, most mail apps won't fetch URL images by default until the user acknowledges the privacy risk.
I think if you want your images to just show up when the mail is opened, inline the image bytes directly into the <img> tag. You base 64-encode the image and stick on a header (e.g. data:image/png;base64, or data:image/jpeg;base64,. That becomes the src attribute.
E.g:
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==" alt="Red dot" />
More details here: https://www.rfc-editor.org/rfc/rfc2397

Email doesn't maintain formatting after sending VB.NET

I am using EASendmail to send emails.The email body is a rich textbox.If i do formatting e.g. One line below another and send the email,the email loses it's formatting. For example if type this :
Hello,
How are you ?
in the rich text box and send it,then it becomes :
Hello,How are you
How do i maintain the text formatting ? And one more thing, if i add any image to my rich textbox, the email body doesn't keep the image ..I mean , the receiver only receives the texts of the email body, not the image. How to fix these issues ?
My code to send email is :
Dim oMail As New SmtpMail("TryIt")
Dim oSmtp As New EASendMail.SmtpClient()
oMail.From = fromtxt.Text
oMail.To = New AddressCollection(totxt.Text)
oMail.Subject = subjecttxt.Text
oMail.HtmlBody = bodytxt.Text
Dim oServer As New SmtpServer(MailConfig.host.Text)
oServer.Port = MailConfig.port.Text
oServer.ConnectType = SmtpConnectType.ConnectSSLAuto
oServer.User = fromtxt.Text
oServer.Password = MailConfig.password.Text
oSmtp.SendMail(oServer, oMail)
EDIT
I even tried :
oMail.HtmlBody = "<html><body>" + bodytxt.Text + "</body></html>"
But no results
This is an easy fix .
All i had to do is convert my RTF to HTML and then send it..RTF-TO-HTML-CONVERTER
After downloading the project files, reference must be added to the .dll files in the bin folder.Then :
Imports Itenso.Rtf.Converter.Html
Imports Itenso.Rtf.Support
Imports Itenso.Rtf
Dim rr As String = bodytxt.Rtf.Replace("\0", "")
Dim rtfDocument As IRtfDocument = RtfInterpreterTool.BuildDoc(rr)
Dim htmlConverter As New RtfHtmlConverter(rtfDocument)
Dim html1 As String = htmlConverter.Convert()
' my other codes in-between(read my post)
oMail.HtmlBody = html1

URL not inserting properly into Outlook message body from string

Dim Urll as string
urll = http://10.0.0.1/Program.exe"
.msgbody = "Click here " & "to open the program"
ends up fragmenting the HTML to where the the URL shows up as a link, but it doesn't use the "Click here" as it's text.
What am I doing wrong?
You probably need to set your message as html
.isBodyHTML = true

MS ACCESS VBA sendobject in email

I have written an email system in ACCESS (Office 10, Windows 7) that works. But I would like to be able to send a formatted document or PDF, etc., something with graphics and text, as the email itself. I have read up on SendObject but I think that sends the document as an attachment, and I would like it to be the email itself. I get emails like that, just want to know how its done.
Thanks for your time
To format the email body with graphics, images custom fonts, and font colors, you would make your email body as HTML, for example:
Dim strBodyMsg AS String
strBodyMsg = "<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US">"
strBodyMsg = strBodyMsg & "<head><title>...</title> </head>"
strBodyMsg = strBodyMsg & "<Body> "
strBodyMsg = strBodyMsg & "your email body message goes here"
strBodyMsg = strBodyMsg & "</Body>"
Also note when you open your email object in VBA.. here is the method
EmailObject.BodyFormat = olFormatHTML

Embedding InfoPath form in email with VBA using SMTP/CDO

I am attempting to do the following:
Use VBA to generate SMTP email
Display InfoPath form embedded in email
This will be linked to an Access database
Unfortunately, I have not been able to configure the outgoing SMTP message correctly using CDO.
I have been building on information found in this post which unfortunately is in C# and some of this functionality doesn't directly map to VB/VBA. Specifically, the "Message.Headers" part is not a property the CDO.Message class has.
I have been able to change the attachments and add them correctly but while the following works:
.fields("urn:schemas:mailheader:Message-Class") = "IPM.InfoPathForm.InfoPath"
.fields("urn:schemas:mailheader:Content-Class") = "InfoPathForm.InfoPath"
the form is not displayed in the email (both the xml and xsn are appearing as attachments and NOT displaying as an embedded form).
In comparing email source between a valid form (generated manually) and invalid (generated proramatically) I have not been able to determine what else I must change. There are several more content tags in the emails, one is:
Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
<html dir=3D"ltr" id=3D"L044F61201A9E6BE2"> <head> <meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Diso-8859-= 1"> </head>
(etc, there is a bunch more)
and another is:
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
And under this there is text from the actual form.
Presumably these sections need to be generated automatically by some setting I am not using correctly.
Here is the code I am using to generate my emails. Note that the two attachments are valid and ones I saved off a form which does display correctly, when I use InfoPath to send the email.
Sub testSendingEmail()
On Error GoTo errHndlr 'boring error handling
Dim myAttach(1 To 2) As String
Dim myContentType(1 To 2) As String
myAttach(1) = "C:\Users\UserID\Desktop\infoPath\outlooksaves\Form1.xml"
myAttach(2) = "C:\Users\UserID\Desktop\infoPath\outlooksaves\Add Projects Table Form.xsn"
myContentType(1) = "application/x-microsoft-InfoPathForm"
myContentType(2) = "application/x-microsoft-InfoPathFormTemplate"
Dim mailMessage As Object
Set mailMessage = CreateObject("CDO.Message")
With mailMessage
.Subject = "Test Automatic Subject 363"
.from = "donotreply#a.com"
.To = "TestEmail#gmail.com"
.AddAttachment myAttach(1)
.AddAttachment myAttach(2)
.Attachments.Item(1).ContentMediaType = myContentType(1)
.Attachments.Item(2).ContentMediaType = myContentType(2)
'testing - this isn't right :(
.fields("urn:schemas:mailheader:Message-Class") = "IPM.InfoPathForm.InfoPath"
.fields("urn:schemas:mailheader:Content-Class") = "InfoPathForm.InfoPath"
With .Configuration.fields
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mailserve"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
'.Item("http://schemas.microsoft.com/cdo/configuration/mailheader:Content-Class") = "InfoPathForm.InfoPath"
.Update
End With
'.BodyPart.ContentClass = "InfoPathForm.InfoPath"
'from C# code
'.Headers.Add "Content-Class", "InfoPathForm.InfoPath"
' .Headers.Add "Message-Class", "IPM.InfoPathForm.InfoPath"
.Send
End With
Exit Sub
errHndlr:
Debug.Print "Error!" & " " & Err.Description
End Sub
I was able to get this working with one extra line. You need to add .fields.update after you add the headers.
This will not show the form in the preview unfortunately, but it will attach it as proper infopath form.
'testing - this isn't right :(
.fields("urn:schemas:mailheader:Message-Class") = "IPM.InfoPathForm.InfoPath"
.fields("urn:schemas:mailheader:Content-Class") = "InfoPathForm.InfoPath"
.fields.update 'Need to update the header fields