# Mail Using SMTP Problem

**URL:** <https://www.ruby-forum.com/t/mail-using-smtp-problem/106799>\
**Category:** Ruby\
**Created:** [June 14, 2007, 8:54am UTC](https://www.ruby-forum.com/t/mail-using-smtp-problem/106799 "2007-06-14T08:54:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dgirdhar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/bc8723/32.png) [@dgirdhar](https://www.ruby-forum.com/u/dgirdhar)\
**Post date:** [June 14, 2007, 8:54am UTC](https://www.ruby-forum.com/t/mail-using-smtp-problem/106799/1 "2007-06-14T08:54:01Z")

</div>

Hi,

```
Please help me to resolve the following issue. When i am running

```

following script after filling all required parameters like mail ID,  
SMTP server and port number etc. I am getting follwoing errors, please  
tell me the reason of errors.

```
msgstr = <<END_OF_MESSAGE
From: Your N. <removed_email_address@domain.invalid>
To: Destination Address <removed_email_address@domain.invalid>
Subject: test message
Date: Sat, 23 Jun 2001 16:26:43 +0900
Message-Id: <removed_email_address@domain.invalid>

This is a test message.
END_OF_MESSAGE

require 'net/smtp'
Net::SMTP.start('your.smtp.server', 25) do |smtp|
  smtp.send_message msgstr,
                    'removed_email_address@domain.invalid',
                    'removed_email_address@domain.invalid'
end

```

Errors:

testmail.rb:16: can’t find string “END\_OF\_MESSAGE” anywhere before EOF  
testmail.rb:1: syntax error, unexpected $end, expecting tSTRING\_CONTENT  
or tSTRI  
NG\_DBEG or tSTRING\_DVAR or tSTRING\_END

Regards:  
Dhiraj

---

<div class="post-metadata">

**Author:** ![dgirdhar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/bc8723/32.png) [@dgirdhar](https://www.ruby-forum.com/u/dgirdhar)\
**Post date:** [June 14, 2007, 9:05am UTC](https://www.ruby-forum.com/t/mail-using-smtp-problem/106799/2 "2007-06-14T09:05:23Z")

</div>

Dhiraj G. wrote:

> ```
> msgstr = <<END_OF_MESSAGE
> From: Your N. <removed_email_address@domain.invalid>
> 
> This is a test message.
> END_OF_MESSAGE
> 
> ```
> 
> testmail.rb:16: can’t find string “END\_OF\_MESSAGE” anywhere before EOF  
> testmail.rb:1: syntax error, unexpected $end, expecting tSTRING\_CONTENT  
> or tSTRI  
> NG\_DBEG or tSTRING\_DVAR or tSTRING\_END

Remove the spaces from in front of the second ‘END\_OF\_MESSAGE’. The end  
of a heredoc string has to be right at the start of the line.

Alternatively at the start of the heredoc do:  
msgstr = \<\<-END\_OF\_MESSAGE  
which allows the end of the heredoc to be indented.

best,  
Dan

---

<div class="post-metadata">

**Author:** ![dgirdhar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/bc8723/32.png) [@dgirdhar](https://www.ruby-forum.com/u/dgirdhar)\
**Post date:** [June 14, 2007, 9:08am UTC](https://www.ruby-forum.com/t/mail-using-smtp-problem/106799/3 "2007-06-14T09:08:24Z")

</div>

Daniel L. wrote:

> Dhiraj G. wrote:
> 
> > ```
> > msgstr = <<END_OF_MESSAGE
> > From: Your N. <removed_email_address@domain.invalid>
> > 
> > This is a test message.
> > END_OF_MESSAGE
> > 
> > ```
> > 
> > testmail.rb:16: can’t find string “END\_OF\_MESSAGE” anywhere before EOF  
> > testmail.rb:1: syntax error, unexpected $end, expecting tSTRING\_CONTENT  
> > or tSTRI  
> > NG\_DBEG or tSTRING\_DVAR or tSTRING\_END
> 
> Remove the spaces from in front of the second ‘END\_OF\_MESSAGE’. The end  
> of a heredoc string has to be right at the start of the line.
> 
> Alternatively at the start of the heredoc do:  
> msgstr = \<\<-END\_OF\_MESSAGE  
> which allows the end of the heredoc to be indented.
> 
> best,  
> Dan

Thanks Dan, it is working.

Regards:  
Dhiraj
