Sign in to follow this  
Followers 0
rosaz

Formatting email body in outlook

12 posts in this topic

Hello,

I'm trying to automate an Outlook email that will have spaces between the lines, like this:

"Hello,

Your request has been received.

Thank you!"

Only I'm not sure how to add the spaces in. I've tried using Chr(10) and so far, no luck. Here's my code:

objOutlook = ObjCreate ("Outlook.Application")

$objOutlook.Session.Logon

$oOApp = ObjCreate("Outlook.Application")

$oOMail = $oOApp.CreateItem($olMailItem)

With $oOMail

.To = $to

.Subject = $subject

.Body = Chr(10) & "Hello," & Chr(10)& Chr(10) & "Your request has been received." & Chr(10) & Chr(10) & "Thank you!"

EndWith

Thank you for any suggestions!

Share this post


Link to post
Share on other sites



Works great, thank you!!

Share this post


Link to post
Share on other sites

You're looking for the @CRLF macro. Instead of Chr(10) use @CRLF.

I'd like to take this "Body" question a little further. Using @CRLF works, but in our case, we need to automate it more.

We have an external program that is actually building all the components (addresses, subject, attachments, body) of the email. We then use this type of email script to present the user with Outlook and all the components are populated for them. Currently our external program is populating an ini file with the all the email components and then the autoit script does IniReadSection to assign varibles that are used in the email script.

This all works great but I am resticted to just a single line of text for the body (no line breaks) because of the variable.

Any thoughts on how I can use a varible (.Body = $bodytext) and have it include line breaks?

Or perhaps is there a way I can use a variable to use a pre-formatted html file to create the body text?

Thanks

Share this post


Link to post
Share on other sites

Use this:

.HTMLBody = "your text <BR><BR>yor second line<BR><BR>more text"

You can use other formatting html tags too.

Share this post


Link to post
Share on other sites

Use this:

.HTMLBody = "your text <BR><BR>yor second line<BR><BR>more text"

You can use other formatting html tags too.

Thanks... the HTMLBody fits the bill perfectly.

From crusing these forums I've figured out alot of the syntax in this type of email script but I'd like to know more. Is this syntax and all the various options listed somewhere? Is it a microsoft spec?

Thanks again for the quick response!

Share this post


Link to post
Share on other sites

Yes , try the msdn . Most of it is there:

http://msdn.microsoft.com/en-us/library/aa210946%28office.11%29.aspx

Share this post


Link to post
Share on other sites

Thanks... the HTMLBody fits the bill perfectly.

From crusing these forums I've figured out alot of the syntax in this type of email script but I'd like to know more. Is this syntax and all the various options listed somewhere? Is it a microsoft spec?

Thanks again for the quick response!

Of course this is documented. Googling for "Outlook.Application HTMLBody" the documentation was result #1.

And from there you should find this pretty quickly:

http://msdn.microsoft.com/en-us/library/aa210946(office.11).aspx

Share this post


Link to post
Share on other sites

Of course this is documented. Googling for "Outlook.Application HTMLBody" the documentation was result #1.

And from there you should find this pretty quickly:

http://msdn.microsoft.com/en-us/library/aa210946(office.11).aspx

Ok.. well thats kinda obvious. Sorry that I had had "forum tunnel focus".

I started digging into this MS documentation and unfortunately they fail to include in this site what the numeric values are for the differant MailItem object properties. http://msdn.microsoft.com/en-us/library/bb207134.aspx is a good example where some user posted the numeric information for them at the bottom of the page.

None the less, this is good resource & I'll just have keep digging to uncover it all. Thanks!

Share this post


Link to post
Share on other sites

Ok.. well thats kinda obvious. Sorry that I had had "forum tunnel focus".

I started digging into this MS documentation and unfortunately they fail to include in this site what the numeric values are for the differant MailItem object properties. http://msdn.microsoft.com/en-us/library/bb207134.aspx is a good example where some user posted the numeric information for them at the bottom of the page.

None the less, this is good resource & I'll just have keep digging to uncover it all. Thanks!

Look at the description:

Returns or sets an OlBodyFormat constant indicating the format of the body text. Read/write.

Click the link: http://msdn.microsoft.com/en-us/library/bb208058.aspx

Specifies the format of the body text of an item.

Name Value Description

olFormatHTML 2 HTML format

olFormatPlain 1 Plain format

olFormatRichText 3 Rich text format

olFormatUnspecified 0 Unspecified format

Share this post


Link to post
Share on other sites

Look at the description:

Returns or sets an OlBodyFormat constant indicating the format of the body text. Read/write.

Click the link: http://msdn.microsoft.com/en-us/library/bb208058.aspx

Specifies the format of the body text of an item.

Name Value Description

olFormatHTML 2 HTML format

olFormatPlain 1 Plain format

olFormatRichText 3 Rich text format

olFormatUnspecified 0 Unspecified format

Thanks again for pointing me in the right direction. I think I would have gotten here eventually, but you have made the discovery process much faster.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0