Email/SMTP::NET Problems

Greetings,

This is my first time posting but this problem I am having is really
annoying.

Here is a section of my code:

fname = cgi[‘fname’]
lname = cgi[‘lname’]
pw = cgi[‘password’]
em = cgi[‘email’]
buf = “

myMessage = <<END_OF_MESSAGE
From: Highpoint A. [email protected]
To: #{fname} #{lname} <#{em}>
Subject: HPU Alumni Verification

Thank you for registering with Highpoint A… Please click the
following link in order to activate your account.

Your password is: #{pw}
END_OF_MESSAGE

Net::SMTP.start('linus.xxxxxx.edu') do |smtp|
           smtp.send_message myMessage,
        '[email protected]', em
  end

end

I’ve x’d out some of the information. But the problem I am having I
think is that it will not allow me to use “em” as an email address to
send. I can physically change em to ‘[email protected]’ and it
will work perfectly fine. I’m taking this email address out of a
POST-REQUEST form so I need the flexibility to store it as a variable
and send whatever that variable the email is. Any suggestions would be
awesome, and if you need more information please let me know.

Brantley

Anyone have any idea of a quick solution?

I’ve tried using:

Net::SMTP.start(‘linus.xxxxxx.edu’) do |smtp|
smtp.send_message myMessage,
[email protected]’, ‘#{em}’
end

and lots other options. I just need to know how I can store the email
address so that I can send the string or whatever. Thanks.

Brantley

It might be that I’m missing something but

‘#{em}’

just looks wrong. Try

“#{em}”

so it gets evaled.

but of course

“#{em}”

is equiv to

em

g phil

ok i had another look at this example, which doesn’t look bad at
all. for i’m not able to find an error i’ve to ask: are you sure that
cgi[‘email’] actually holds the emailaddress desired? Does the
emailaddress appear in the generated content of the message?

g phil

Phil,

Thanks for replying. I attempted that method as well and it does not
work either, as you said it is equiv to em. I’ve been constantly
browsing the net to find a solution, but nothing is coming up. Any other
ideas that pop up let me know. Thanks in advance.

Brantley

This simple problem has caused me more grief than I think its worth
honestly :frowning:

Brantley

Yes it does hold the email, I comment out the attempt on sending the
email, and just print out the em like this:

buf+=“em is: #{em}

which produces:

[email protected]

on the screen. So…I think that does answer your question

Brantley

Bill,

Thank you for your response. I put myMessage into the buffer and it
printed out the entire message as follows:

From: Highpoint A. To: brantley shields Subject: HPU Alumni
Verification Thank you for registering with us. Please click the
following link to activate your account.
http://xxxx.higxxxxnt.edu/~xxxxs/alumni/verify.rbx Your password is:
xxxx

Now as you can see, the #{em} did not print out the the To: statement,
but I’m not sure that it should in this instance. So I made another line
that says this:

buf += “Email is: #{em}
” results:
[email protected]

So it seems as if em is getting the email address, but I’m still
completely lost as to why I cannot use this string to send the
emailaddress. I’ve changed the email to [email protected] to make sure
the underscore was not causing any problems but same problem occurs.
Thanks for your time!

Brantley

From: “Brantley Shields” [email protected]

on the screen. So…I think that does answer your question
What if you print the whole myMessage to the buffer?

For ex:

buf << “

#{CGI.escapeHTML(myMessage)}

…so that we can see exactly what is being substituted for ‘em’ in the
email?

Regards,

Bill

On Apr 23, 2008, at 11:18 PM, Brantley Shields wrote:

From: Highpoint A. To: brantley shields Subject: HPU Alumni
Verification Thank you for registering with us. Please click the
following link to activate your account.
http://xxxx.higxxxxnt.edu/~xxxxs/alumni/verify.rbx Your password is:
xxxx

this can’t be correct. your code has ‘<’ and ‘>’ around the addr but
those are not there - did you use CGI.escapeHTML??

another thought - do not use to_s to check out your email addr - use

“em: #{ CGI.escapeHTML em.inspect }

i think you’ve got something like a stray newline or html char horking
things up.

a @ http://codeforpeople.com/

buf+="em: #{ CGI.escapeHTML em.inspect }
"
returns:
em: “[email protected]

I’m not sure where your going with this, I’m sure you can tell I’m new
to Ruby. Thanks for having a look, let me know what you think

Brantley

Brantley Shields wrote:

buf+=“em: #{ CGI.escapeHTML em.inspect }

returns:
em: “[email protected]

I’m not sure where your going with this, I’m sure you can tell I’m new
to Ruby. Thanks for having a look, let me know what you think

Brantley

buf+=“myMessage: #{ CGI.escapeHTML myMessage.inspect }

returns:

myMessage: “From: Highpoint A. [email protected]\nTo:
brantley shields [email protected]\nSubject: HPU Alumni
Verification\n\nThank you for registering with us. Please click the
following link to activate your
account.\nhttp://linus.highpoint.edu/~bshields/alumni/verify.rbx\nYour
password is: cagenu\n”

Sorry for double post, I think this is useful

Brantley

On Apr 23, 2008, at 8:50 PM, Brantley Shields wrote:

Net::SMTP.start(‘linus.xxxxxx.edu’) do |smtp|
smtp.send_message myMessage,
[email protected]’, ‘#{em}’
end

you need

Net::SMTP.start(‘linus.xxxxxx.edu’) do |smtp|
smtp.send_message myMessage, ‘[email protected]’, em
end

is all i think.

a @ http://codeforpeople.com/

On Apr 23, 2008, at 11:37 PM, Brantley Shields wrote:

password is: cagenu\n"

Sorry for double post, I think this is useful

so there you go - the address is right there. what’s the issue now?

a @ http://codeforpeople.com/

I thought the same,

I knew em was holding the email address just fine, but you can’t stick
em on the end and it just send the email, I can’t put anything other
than ‘[email protected]’ otherwise I get an error…Not sure
how to get around this is my point…

Brantley

It is:

Net::SMTP.start(‘mail.my.com’) do |smtp|
smtp.send_message myMessage, ‘[email protected]’, send_to
end

My question is. Are you sure that em = cgi[‘email’] is a String object?
Try to use em.to_s.

by
TheR

On Apr 23, 2008, at 11:56 PM, Brantley Shields wrote:

I thought the same,

I knew em was holding the email address just fine, but you can’t stick
em on the end and it just send the email, I can’t put anything other
than ‘[email protected]’ otherwise I get an error…Not
sure
how to get around this is my point…

Brantley

just realized - you have the arguments reversed

it’s

msg, to, from

not

msg, from, to

which is what you have i think

a @ http://codeforpeople.com/

On Behalf Of Brantley Shields

I knew em was holding the email address just fine, but you

can’t stick

em on the end and it just send the email, I can’t put anything other

than ‘[email protected]’ otherwise I get an

error…Not sure

how to get around this is my point…

you seem to be doing web thingy, so

1 pls replace em with another variable email or address will do. we try
to avoid template clobbering…

2 when posting problems pls show logs fr client and fr server

3 put debugging options on your code, eg using net/smtp, i usually do,

smtp.set_debug_output $stderr # verbose output mail session

kind regards -botp

No, i think he has them the right way around. I can’t see anything wrong
with what Brantley is doing though. I’ve included some code that I use
that
does pretty much the same thing, and I know it works. The only real
difference, is I haven’t used <<HEREDOC syntax. But it does the same
thing.
Hopefully this will help.

The email is going from the student, to the trainer.

def submit_results(sid, cid, aid, results)
student = ::Student[sid]
result = student.submit_results(cid, aid, results)
trainer = student.get_trainer(cid)
course = ::Course[cid]
assessment = ::Assessment[aid]
submissionEmail = “From: #{student.first_name} #{student.last_name}
<#{student.email}>\n”
submissionEmail += “To: #{trainer.first_name} #{trainer.last_name}
<#{trainer.email}>\n”
submissionEmail += "Subject: Assessment Submission: ‘#{course.name}’

‘#{assessment.name}’\n\n"
submissionEmail += “#{student.first_name} has submitted results for
‘#{
assessment.name}’ in ‘#{course.name}’.\n”
submissionEmail += “Please log in to mark #{student.first_name}'s
answers.\n\n”
Net::SMTP.start(‘localhost’) {|smtp|
smtp.send_message(submissionEmail,
student.email, trainer.email)}
result
end

On Thu, Apr 24, 2008 at 3:58 PM, ara.t.howard [email protected]
wrote:

“Every child has many wishes. Some include a wallet, two chicks and a
cigar,
but that’s another story.”

Greetings,

I’ve found some information that may be useful to those helping me on
this small project. The following code works just fine:

from_address = ‘[email protected]
to_address = ‘[email protected]
Net::SMTP.start(‘linus.highpoint.edu’) do |smtp|
smtp.send_message(myMessage,from_address,to_address)
end

So, what is the difference between " and ’ to ruby? I checked the error
logs on my server (got ahold of the administrator) and the logs show a
tainted to_address. I know the email itself is not tainted and that it
will send an email address to the one being put into to_address. I’ve
tried multiple simple email addresses such as “[email protected]” which
would not be tainted. So I think its confusing the string or whatever
to_address is being referred to as, its interpretting it as something
else. how can I convert to_address to ‘somelikethis’ ?

Brantley