# Attachement corrupt

**URL:** <https://www.ruby-forum.com/t/attachement-corrupt/109039>\
**Category:** Rails\
**Created:** [July 10, 2007, 8:27pm UTC](https://www.ruby-forum.com/t/attachement-corrupt/109039 "2007-07-10T20:27:50Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daskandonga](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@Daskandonga](https://www.ruby-forum.com/u/Daskandonga)\
**Post date:** [July 10, 2007, 8:27pm UTC](https://www.ruby-forum.com/t/attachement-corrupt/109039/1 "2007-07-10T20:27:50Z")

</div>

I’m using ActionMailer to send an e-mail with attachement, but I  
receive the same e-mail attachement corrupted.

How I can resolve that?

The enviroment is:

- Windows
- Microsoft Exchange Server.

Code Enviroment.rb:

1. ActionMailer::Base.delivery\_method = :smtp
2. 
3. ActionMailer::Base.smtp\_settings = {
4. :address =\> ‘nome\_do\_servidor’,
5. :port =\> 25,
6. :domain =\> nil
7. }

Code Method to send e-mail:

1. def enviar(mensagem)
2. @subject = mensagem.assunto
3. @body = {:mensagem =\> mensagem}
4. @recipients = mensagem.para
5. @from = [mensagem.de](http://mensagem.de)
6. @sent\_on = Time.now
7. @headers = {}
8. 
9. unless mensagem.arquivos.blank?
10. 

```
arquivo = mensagem.arquivos

```

11. 

```
attachment(:filename => File.basename(arquivo)) do |a|

```

12. 

```
  file = File.open(arquivo, 'r+') {|f| a.body =

```

f.read}  
13. end  
14. end  
15. end

Thanks,

Daskandonga
