Jump to content

Sending Email in Plain Text


bartekd
 Share

Recommended Posts

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

"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?

Link to comment
Share on other sites

  • 2 weeks later...

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...