MS ACCESS VBA sendobject in email - vba

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

Related

VB.Net Hyperlinking in EWS email with class properties

I need help getting the hyperlink to work as well as getting the value stored in YestFile.FileName to show up.
I have a list of objects of class FileFromYesterday (Collection2) with 3 properties. Two properties are just Strings (FileName and Entity) but one property (URL) contains a URL as a String. I am trying to hyperlink the URL to FileName in the main.
I have a feeling that I need to use HTML to format the email somehow but I have no Idea where to begin
Dim HyperLink As String
Dim FileLine As String
Dim NewBody As String
Dim message As New EmailMessage(EWS)
message.Subject = "Monthly Financial Imported into Docushare on " & String.Format("{0:MM-dd-yyyy}", Yesterday)
NewBody = "Total of " & Collection2.Count & " Files Imported." & "\n"
For Each YestFile In Collection2
HyperLink = YestFile.FileName.Replace(".pdf", "")
FileLine = HyperLink & "Entity: " & YestFile.Entity & Environment.NewLine
NewBody = NewBody & FileLine
Next
You should be creating a HTML document in your NewBody varible so you need the pre and post tags for a HTML document eg
<html>
<body>
</body>
</html>
the body content you want should go within between the Body Tags and for thing like NewLines you need to use the appropriate HTML tags such as
<br />
Eg what ever you end up creating in you NewBody variable you should be able to write out to a file or test in any Online HTML validator https://validator.w3.org/#validate_by_input to see if its valid and how it will look before trying to send it.

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

VBA Code to change font and size in an email from access

I have an access form that runs a query. There is a command button on the form that I want to send an email with the query results attached in an excel spreadsheet. Using the code below I am able to attach the results and send the email ok. I would like to be able to format the email body so that it is more noticeable. I'm not really sure how to go about doing this and still have my query attached. I have also created an email template that I would use but I haven't been able to figure out how to use the template and attach the query results. I'm open for any suggestions. Any help would be greatly appreciated.
DoCmd.SendObject acQuery, "BoxOrder", "ExcelWorkbook(*.xlsx)", "me#home.com", _
"John#hishome.com", "", "BOX ORDER", _
"ALL BOXES STITCHED" & vbCrLf & "Questions: Please Call Me" & _
vbCrLf & "555-555-5555 x 66654", True, True
You could follow the Article from MS.
A proportion of the code is as follows:
Set ola1 = New Outlook.Application
Set mai1 = ola1.CreateItem(olMailItem)
mai1.To = strTo
mai1.Subject = strSubj
If bolHTML = True Then
mai1.HTMLBody = strBody
Else
mai1.Body = strBody
End If
mai1.Display
If you use the HTML (set bolHTML = True) version you can either have an RTF control on a Form and pass the formatted text over or hardcode your HTML with the formatting you need. Just set the "strBody" to the message you want.
Then you need to look into the Attachments.Add (MS Article) if you want to use the above code with your original purpose.
There's a full 599CD Email Seminar you could follow if you're going to be doing a lot with Email in Access.

MailMessage removing consecutive spaces

I'm using an SmtpClient object to send a MailMessage from one MailAddress to another. I'm trying to format the body of the MailMessage to look centered using a monospace font, but the consecutive spaces are always being replaced by a single space.
So:
With smtpMessage
.IsBodyHtml = True
.Body = "<body style=""font-family:monospace"">"
.Body &= " ************************************************************<br>"
.Body &= " * This email was generated by an automated system. *<br>"
.Body &= " * Please do not reply to this email. *<br>"
.Body &= " ************************************************************<br>"
.Body &= "</body>"
End With
Is being received as:
************************************************************
* This email was generated by an automated system. *
* Please do not reply to this email. *
************************************************************
I've searched around but all I'm finding are topics about line breaks not displaying properly, nothing about the spaces themselves.
The spaces are removed not by MailMessage, but by the use of HTML. HTML standard is to ignore extra spaces. If you truly wish to keep the extra spaces, you should either add the "<pre>" tag, or use .
In HTML, multiple spaces in code are replaced by one space. You can try to force a space to appear.
OR you can try composing your message as plain text (IsHtml = false) (and remove any HTML from message body).

How to put a hyperlink into the email body using 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