INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

insert lines of txt in body email

insert lines of txt in body email

(OP)
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

RE: insert lines of txt in body email

.BODY = strText & CreateObject("scripting.filesystemobject").OpenTextFile(STRING_TXT).ReadAll

RE: insert lines of txt in body email

You can also do this:

CODE

With objMsg
    .SentOnBehalfOfName = "KL"
    .To = OI
    .CC = "KL"
    .Subject = "Oggetto Ko" & " - " & NOMINATIVO & " - " & N
    Open STRING_TXT For Input As #1
    .BODY = strText & vbNewLine & Input$(LOF(1), 1)
    Close #1
    'Debug.Print strText & STRING_TXT 
    .Display
   '.Send
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.

RE: insert lines of txt in body email

(OP)
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!

RE: insert lines of txt in body email

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.

RE: insert lines of txt in body email

.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

RE: insert lines of txt in body email

(OP)
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

RE: insert lines of txt in body email

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.

RE: insert lines of txt in body email

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:

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

RE: insert lines of txt in body email

Hello? Did any of the above help?

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close