# Smtp - from field shows up blank in client

**URL:** <https://www.ruby-forum.com/t/smtp-from-field-shows-up-blank-in-client/129350>\
**Category:** Ruby\
**Created:** [February 17, 2008, 8:10am UTC](https://www.ruby-forum.com/t/smtp-from-field-shows-up-blank-in-client/129350 "2008-02-17T08:10:26Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Max\_Payne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a587f6/32.png) [@Max\_Payne](https://www.ruby-forum.com/u/Max_Payne)\
**Post date:** [February 17, 2008, 8:10am UTC](https://www.ruby-forum.com/t/smtp-from-field-shows-up-blank-in-client/129350/1 "2008-02-17T08:10:26Z")

</div>

Hello,  
I’m using the following code which is working fine except the from  
address comes up blank.

smtp = Net::SMTP.start(‘[smtp.mydomain.com](http://smtp.mydomain.com)’, 587, ‘[mydomain.com](http://mydomain.com)’,  
‘removed\_email\_address@domain.invalid’, ‘password’, :login) { |smtp|  
smtp.send\_message( msg, ‘removed\_email\_address@domain.invalid’,  
[‘removed\_email\_address@domain.invalid’] )  
}  
The email goes out but it doesn’t tell me who it’s from.  
In gmail the from is (Unknown Sender), In yahoo or others it’s blank.  
What am I missing?

---

<div class="post-metadata">

**Author:** ![Max\_Payne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a587f6/32.png) [@Max\_Payne](https://www.ruby-forum.com/u/Max_Payne)\
**Post date:** [February 17, 2008, 8:28am UTC](https://www.ruby-forum.com/t/smtp-from-field-shows-up-blank-in-client/129350/2 "2008-02-17T08:28:00Z")

</div>

Max Payne wrote:

> In gmail the from is (Unknown Sender), In yahoo or others it’s blank.  
> What am I missing?

Hello Max,

I think the from/to/subject needs to be part of your message, like this:  
msg = \<\<EOF  
From: Me [my@address](mailto:my@address)  
To: You [your@address](mailto:your@address)  
Subject: This email is a test.

This is the start of the message body…  
EOF

Good luck,  
Dan

---

<div class="post-metadata">

**Author:** ![Max\_Payne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a587f6/32.png) [@Max\_Payne](https://www.ruby-forum.com/u/Max_Payne)\
**Post date:** [February 17, 2008, 9:01am UTC](https://www.ruby-forum.com/t/smtp-from-field-shows-up-blank-in-client/129350/3 "2008-02-17T09:01:27Z")

</div>

Dan Z. wrote:

> > The email goes out but it doesn’t tell me who it’s from.  
> > To: You [your@address](mailto:your@address)  
> > Subject: This email is a test.
> 
> This is the start of the message body…  
> EOF
> 
> Good luck,  
> Dan

Also, if you’re missing the date, you’ll need to add that in. Check out  
the example on my page here:  
[http://notepad.onghu.com/2007/3/26/sending-email-with-ruby](http://notepad.onghu.com/2007/3/26/sending-email-with-ruby)

Cheers,  
Mohit.  
2/17/2008 | 4:00 PM.

---

<div class="post-metadata">

**Author:** ![Max\_Payne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a587f6/32.png) [@Max\_Payne](https://www.ruby-forum.com/u/Max_Payne)\
**Post date:** [February 17, 2008, 4:15pm UTC](https://www.ruby-forum.com/t/smtp-from-field-shows-up-blank-in-client/129350/4 "2008-02-17T16:15:30Z")

</div>

On Feb 17, 3:00 am, Mohit S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > }  
> > > Subject: This email is a test.  
> > > Cheers,  
> > > Mohit.  
> > > 2/17/2008 | 4:00 PM.- Hide quoted text -
> 
> - Show quoted text -

Thanks , putting it all in the message did the trick. Mohit thanks for  
the great example. Now I need to figure out how to CC. The  
send\_message method takes a to and a from…

---

<div class="post-metadata">

**Author:** ![Max\_Payne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a587f6/32.png) [@Max\_Payne](https://www.ruby-forum.com/u/Max_Payne)\
**Post date:** [February 17, 2008, 5:03pm UTC](https://www.ruby-forum.com/t/smtp-from-field-shows-up-blank-in-client/129350/5 "2008-02-17T17:03:20Z")

</div>

Max Payne wrote:

> On Feb 17, 3:00 am, Mohit S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > Also, if you’re missing the date, you’ll need to add that in. Check out  
> > the example on my page here:[http://notepad.onghu.com/2007/3/26/sending-email-with-ruby](http://notepad.onghu.com/2007/3/26/sending-email-with-ruby)
> 
> Thanks , putting it all in the message did the trick. Mohit thanks for  
> the great example. Now I need to figure out how to CC. The  
> send\_message method takes a to and a from…

Hi Max

I’ve never tried CC, so I don’t know. But, if you do get it, please  
post here for future reference - I’ll also update the example on my page  
after that.

Cheers,  
Mohit.  
2/18/2008 | 12:02 AM.

---

<div class="post-metadata">

**Author:** ![Max\_Payne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a587f6/32.png) [@Max\_Payne](https://www.ruby-forum.com/u/Max_Payne)\
**Post date:** [February 17, 2008, 6:26pm UTC](https://www.ruby-forum.com/t/smtp-from-field-shows-up-blank-in-client/129350/6 "2008-02-17T18:26:05Z")

</div>

On Feb 17, 11:01 am, Mohit S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi Max
> 
> I’ve never tried CC, so I don’t know. But, if you do get it, please  
> post here for future reference - I’ll also update the example on my page  
> after that.
> 
> Cheers,  
> Mohit.  
> 2/18/2008 | 12:02 AM.

I added a cc\_mail var and an extra parameter for send\_message and it  
worked although I didn’t completely test. I received a [You were Cc’d]  
message on my blackberry so I’m thrilled. If I had more cc’s then I  
would have used an array of email addresses.

cc\_mail = ‘removed\_email\_address@domain.invalid’

msg = \<\<EOF  
From: #{from\_name}\<#{from\_mail}\>  
To: #{to\_name}\<#{to\_mail}\>  
Cc: #{cc\_mail}  
Subject: E&D upload complete.

#{body}  
Powered By Ruby  
EOF

smtp = Net::SMTP.start(smtp\_host, smtp\_port, smtp\_domain, smtp\_user,  
smtp\_password, :login) { |smtp|  
smtp.send\_message(msg,smtp\_user,to\_mail,cc\_mail)  
}

---

<div class="post-metadata">

**Author:** ![Max\_Payne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a587f6/32.png) [@Max\_Payne](https://www.ruby-forum.com/u/Max_Payne)\
**Post date:** [June 24, 2009, 8:35am UTC](https://www.ruby-forum.com/t/smtp-from-field-shows-up-blank-in-client/129350/7 "2009-06-24T08:35:41Z")

</div>

Hi All,

I am facing a unique problem. Even though I am setting all the  
parameters as found in many of the turorials, I am not getting the  
subject header in the mail.

The code used :

msgstr = \<\<EOF  
From: My Name [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
To: Another Name [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Subject: test message  
Date: Sat, 23 Jun 2001 16:26:43 +0900  
Content-type: text/html

```
This is a test message.

```

EOF

from = ‘removed\_email\_address@domain.invalid’  
to = ‘removed\_email\_address@domain.invalid’

Net::SMTP.start(‘my.mail.server’, 25) do |smtp|  
smtp.send\_message msgstr,from,to  
end

The from is appearing in the mail from field, but the subject is not  
getting populated. Please help me in this issue.

Thanks and Regards,  
Anand.

---

<div class="post-metadata">

**Author:** ![Max\_Payne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a587f6/32.png) [@Max\_Payne](https://www.ruby-forum.com/u/Max_Payne)\
**Post date:** [June 24, 2009, 8:48am UTC](https://www.ruby-forum.com/t/smtp-from-field-shows-up-blank-in-client/129350/8 "2009-06-24T08:48:01Z")

</div>

Hi,

2009/6/24 Anand S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Â Â To: Another Name Â [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> Net::SMTP.start(‘my.mail.server’, 25) do |smtp|  
> Â smtp.send\_message msgstr,from,to  
> end
> 
> The from is appearing in the mail from field, but the subject is not  
> getting populated. Please help me in this issue.

You should remove spaces in front of each lines like this:

msgstr = \<\<EOF  
From: My Name [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
To: Another Name [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Subject: test message  
Date: Sat, 23 Jun 2001 16:26:43 +0900  
Content-type: text/html

This is a test message.  
EOF

Regards,  
Park H.

---

<div class="post-metadata">

**Author:** ![Max\_Payne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a587f6/32.png) [@Max\_Payne](https://www.ruby-forum.com/u/Max_Payne)\
**Post date:** [June 24, 2009, 9:28am UTC](https://www.ruby-forum.com/t/smtp-from-field-shows-up-blank-in-client/129350/9 "2009-06-24T09:28:40Z")

</div>

Thank you very much for the prompt reply. That worked …
