# Finding out in-memory size of an email

**URL:** <https://www.ruby-forum.com/t/finding-out-in-memory-size-of-an-email/155820>\
**Category:** Ruby\
**Created:** [December 17, 2008, 8:40am UTC](https://www.ruby-forum.com/t/finding-out-in-memory-size-of-an-email/155820 "2008-12-17T08:40:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![petrjanda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ee7513/32.png) [@petrjanda](https://www.ruby-forum.com/u/petrjanda)\
**Post date:** [December 17, 2008, 8:40am UTC](https://www.ruby-forum.com/t/finding-out-in-memory-size-of-an-email/155820/1 "2008-12-17T08:40:50Z")

</div>

Hi all,  
I have a script that executes sendmail binary like this

exec ‘/usr/sbin/sendmail’

This opens op the sendmail STDIN that waits for the email to be typed or  
inputed via other means(postfix). Is it at all possible to actually  
find out the size of the email(in bytes) thats going into sendmail?

Petr

---

<div class="post-metadata">

**Author:** ![petrjanda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ee7513/32.png) [@petrjanda](https://www.ruby-forum.com/u/petrjanda)\
**Post date:** [December 17, 2008, 12:18pm UTC](https://www.ruby-forum.com/t/finding-out-in-memory-size-of-an-email/155820/2 "2008-12-17T12:18:14Z")

</div>

Petr J. wrote:

> I have a script that executes sendmail binary like this
> 
> exec ‘/usr/sbin/sendmail’
> 
> This opens op the sendmail STDIN that waits for the email to be typed or  
> inputed via other means(postfix). Is it at all possible to actually  
> find out the size of the email(in bytes) thats going into sendmail?

Not sure how this relates to Ruby.

If your ruby script is using ‘exec’ like that, then it is _replacing_  
the entire Ruby interpreter with sendmail. At that point, sendmail is  
running, accepting data on stdin, and Ruby has terminated. So sendmail  
knows the size of the E-mail, but there is no-one to tell.

Perhaps what you want is to keep Ruby running while sending data to  
sendmail, e.g. (untested)

count = 0  
IO.popen("/usr/sbin/sendmail",“w”) do |sendmail|  
while data = $stdin.read(4096)  
sendmail \<\< data  
count += data.size  
end  
end  
STDERR.puts “Thank you. You sent #{count} bytes.”
