Jump to content
Sign in to follow this  
bartekd

Sending Email in Plain Text

Recommended Posts

bartekd

I want to automate an email that comes in frequently. I have everything setup, but what I can't figure out is how to make the email send in plain text. the below will send the email in Rich text, but I need it in plain text (looks more professional with the format of my email, and is half the size)

This is what I have

CreateMailItem()

Func CreateMailItem()

Local $olMailItem = 0

Local $olFormatrichText = 3

Local $olImportanceLow = 0

Local $olImportanceNormal= 1

Local $olImportanceHigh = 2

$oOApp = ObjCreate("Outlook.Application")

$oOMail = $oOApp.CreateItem($olMailItem)

With $oOMail

.To = ("Email@Email.com")

.Subject = "Subject " ; subject from the email - can be anything you want it to be

; .BodyFormat = $olFormatrichText

.Importance = $olFormatrichText;$olImportanceHigh

.Body = "Test 1st line" & @CRLF & "Test 2nd line"

.attachments.add ("c:\Test1.txt" )

.attachments.add ("c:\test2.txt")

.Display

.Send

EndWith

EndFunc

Share this post


Link to post
Share on other sites
Juvigy

Constant Value

olFormatHTML 2

olFormatPlain 1

olFormatRichText 3

olFormatUnspecified 0

Just replace olFormatRichText with olFormatPlain

Share this post


Link to post
Share on other sites
Zedna

Instead of

With $oOMail
.Body = "Test 1st line" & @CRLF & "Test 2nd line"

Use

With $oOMail
.TextBody = "Test 1st line" & @CRLF & "Test 2nd line"

EDIT: Sorry I reread your question, my solution is only for CDO.Message not for Outlook

Consider using CDO.Message object instead of Outlook.

There is nice UDF wrapper for this: Smtp Mailer from Jos

http://www.autoitscript.com/forum/index....x.php?showtopic=23860&hl=CDOMessage&st=0

Edited by Zedna

Share this post


Link to post
Share on other sites
bartekd

the formatplain doesn't work, it gives me this

(17) : ==> The requested action with this object has failed.:

.BodyFormat = $olFormatplain

.BodyFormat = $olFormatplain^ ERROR

Is there an include that I need to include in this script? I can't get it to work.

Share this post


Link to post
Share on other sites
Juvigy

Do you have :

Local $olFormatPlain=1

In your script?

Share this post


Link to post
Share on other sites
water

Maybe the Outlook UDF can help. Function _OutlookSendMail() should do what you want or at least give you some inspiration.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
Juvigy

I think it is clear for everyone ?

.BodyFormat can have 4 values:

Constant Value
olFormatHTML 2
olFormatPlain 1
olFormatRichText 3
olFormatUnspecified 0

Just change accordingly as needed. You have to put

.BodyFormat=1 for plaintext and .BodyFormat=3 for rich text.

Share this post


Link to post
Share on other sites
bartekd

Thanks but I can't get it to work

This is my script

CreateMailItem()

Func CreateMailItem()

Local $olFormatHTML = 2

Local $olFormatPlain = 1

Local $olFormatRichText = 3

Local $olFormatUnspecified = 0

Local $olMailItem = 0

;Local $olFormatPlain = 3

;Local $olFormatPlain=1

;Local $olImportanceLow = 0

;Local $olImportanceNormal= 1

;Local $olImportanceHigh = 2;

$oOApp = ObjCreate("Outlook.Application")

$oOMail = $oOApp.CreateItem($olMailItem)

With $oOMail

.To = ("bla@bla.com")

.Subject = "Subject " ; subject from the email - can be anything you want it to be

.BodyFormat = 1

.Body = "ALLBUDD" & @CRLF & "";

.attachments.add ("c:\1.txt")

.Display

.Send

EndWith

EndFunc

Share this post


Link to post
Share on other sites
Juvigy

And what exactly is not working?

Your script works on my PC

Share this post


Link to post
Share on other sites
water

Works on my PC (Windows XP, Outlook 2002, Autoit 3.3.0.0) as well


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
bartekd

I get this error

(25) : ==> The requested action with this object has failed.:

.BodyFormat = $olFormatPlain

.BodyFormat = $olFormatPlain^ ERROR

I have office 2000.

Edited by bartekd

Share this post


Link to post
Share on other sites
bartekd

do I need to include some other file, or can someone test this that has office 2k?

Share this post


Link to post
Share on other sites
Juvigy

change .BodyFormat = $olFormatPlain to .BodyFormat = 1

Share this post


Link to post
Share on other sites
bartekd

then I get the same error type.

==> The requested action with this object has failed.:

.BodyFormat = 1

.BodyFormat = 1^ ERROR

Share this post


Link to post
Share on other sites
Juvigy

It works for me. Seems outlook 2000 doesnt have all the properties and methods (or they are changed).

Try removing .BodyFormat and leave only .Body = "ALLBUDD" & @CRLF & "";

How does it work now?

Share this post


Link to post
Share on other sites
bartekd

I tried that, and it sends the email, but it is in rich text.

Share this post


Link to post
Share on other sites
Juvigy

"If there is a particular person in your contacts list that would rather you didn't mail him/her HTML or enhanced e-mail you can set them to receive only plain text e-mail.Click on CONTACTS and then click on the appropriate name in your address book. Just below their e-mail address will be a tag which you can tick to make sure they only get your e-mail in Plain Text."

Maybe this is going to work?

Share this post


Link to post
Share on other sites
bartekd

Thanks for thinking outside the box. :)

But this won't work for me becuse I send this email to the same people I want to send and receive regular emails for as well.

Any other thoughts?

Share this post


Link to post
Share on other sites
bartekd

can someone that has outlook 2000 installed on their PC try this script out and let me know if it is the same error message?

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.