Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

insert lines of txt in body email

Status
Not open for further replies.

2009luca

Programmer
Jul 27, 2013
222
IT
I just have a STRING_TXT="c:\muydir\Test.txt"

In txt file are:
line1aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
line2bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
line3cccccccccccccccccccccccccccccccc
...
lineNzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz

Now i need to get all line from txt and insert in body of email.

my part of code to send email is:

Set objApp = CreateObject("Outlook.Application")
Set objMsg = objApp.CreateItem(0)

With objMsg
.SentOnBehalfOfName = "KL"
.To = OI
.CC = "KL"
.Subject = "Oggetto Ko" & " - " & NOMINATIVO & " - " & N
.BODY = strText & STRING_TXT
Debug.Print strText & STRING_TXT
.Display
'.Send
End With

Set objApp = Nothing
Set objMsg = Nothing

actually the result in body email is:

Mytest
"c:\muydir\Test.txt"

but i need in body e mail:
Mytest
line1aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
line2bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
line3cccccccccccccccccccccccccccccccc
...
lineNzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
 
[tt].BODY = strText & CreateObject("scripting.filesystemobject").OpenTextFile(STRING_TXT).ReadAll[/tt]
 
You can also do this:

Code:
With objMsg
    .SentOnBehalfOfName = "KL"
    .To = OI
    .CC = "KL"
    .Subject = "Oggetto Ko" & " - " & NOMINATIVO & " - " & N[blue]
    Open STRING_TXT For Input As #1
    .BODY = strText & vbNewLine & Input$(LOF(1), 1)
    Close #1[/blue][green]
    'Debug.Print strText & STRING_TXT [/green]
    .Display[green]
   '.Send[/green]
End With

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
Ok tks to the all!
But in txt have
Aaaaaaaaa bbbbbbbbb ccccccc
Aaaaaaaaa bbbbbbbbb ccccccc
In body of email with code have:
Aaaaaaaaa bbbbbbbbb ccccccc
Aaaaaaaaa bbbbbbbbb ccccccc

In effect the code don't maintain the correct original alignment!
 
Looks exactly the same to me, I cannot see any difference between the two...

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
.txt files typically don't have any layout. If there is an apparent difference it is related to the tool being used to display the content
 
ok....i have understand the prob!
txt line in email body not have correct format, beacuse txt file donat accept any format of font!
I need to format in currier new (is formatted font) only the piece of code of the lines in STRING_TXT

 
You can send the e-mail as HTML and have control over the font used to display a message, or - if you use Outlook - you can set plain text messages with the default font of courier New:
File - Options - Mail - Compose Messages - Stationary and Fonts - Composing and reading plain text messages (set the Font here to Courier New)

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
Simple body text in an email cannot have a font assigned. It displays with whatever font the recipient's email client uses.

So you need to add it as HTMLBody or RTFBody instead, e.g. something like:

[tt].HTMLBody = strText & "<FONT FACE='courier new'>" & STRING_TXT & "</FONT>"[/tt]

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top