Good Afternoon, I am trying to get my application ...
# box-products
o
Good Afternoon, I am trying to get my application to send an email. When I check the logs it says bad Username & Password. However when I verify the connection I get a success message which contradicts the logs. Any ideas?
a
Am interested in why this is something to do with Box products, when everything you have thusfar said just relates to Lucee's inbuilt mailer. But anyway. It's pretty much impossible to comment on why your code is erroring without seeing the code in question.
o
This is related to Lucee itself and not directly to CFML code as far as I know. I can move it if you want. Anyways here is the code I am using:
Copy code
var protocol = #getPageContext().getRequest().getScheme()#;
				var domain = #cgi.server_name#;
				var path = #cgi.path_info#;
				mailService = new mail(
					to = rc.email,
					from = "admin@#domain#",
					subject = "Password Reset Instructions",
					body = """
					A request has been sent to reset your password.\n
					Click on the link below to reset your password.\n
					\n

					#protocol#://#domain#/resetpassword/#token#
					"""
					);
					mailService.send();
d
Have you configured the email service's user name and password in the admin? You're not passing it here that I can see.
o
Yes I posted screenshots showing it as verifying successfully in the original post.

https://files.slack.com/files-pri/T06T9JEE9-F03UURUKG3Y/email_verify_success.pngā–¾

a
I can move it if you want.
It'd be more likely to get the more eyes on it if you post things in the correct channel.
OK I'm not so au fait with the inner workings of Lucee's mail service. Have you tried with just a
<cfmail>
tag as a baseline/control experiment?
I can't see anything wrong with yer code though.
o
Sorry I figured Lucee means box and cfml-general means code related as in no lucee, coldfusion server etc. You can move it.
d
Sorry, drive-by comment on my way out the door. Also, small thing, but it'll make your code cleaner. You don't need pound signs around variable names in cfscript unless it's inside a string. So not here:
Copy code
var domain = #cgi.server_name#;
Yes here:
Copy code
from = "admin@#domain#"
a
Box means "Ortus products", like CommandBox / ColdBox / TestBox etc.
o
Isn't Lucee owned by Orthus?
a
No
Would probably be better if it was, but... no.
o
Wow egg on my face seriously, I thought they owned it cause their name is everywhere. šŸ¤•
a
Lucee is an open source project who will admit to there being a core "Lucee Association Switzerland" administering it when it's convenient for them to say so ("you can give us money if you like... send it to LAS"), but they also deny that LAS really means anything when that is convenient for them ("you can't expect LAS to do anything about Lucee as it's just a concept not actually a thing"). #itsComplicated #notReally
o
Removing the extra # # didn't work šŸ˜ž
a
Anyway, don't sweat that stuff, it won't help you. Try a
<cfmail>
tag and see what you get.
Nah the advice re
#
was just "better coding practices" nothing to do with yer issue.
r
Anecdotally, trying to use Gmail for outgoing email is notoriously hard. I’d suggest using something like Mailgun. They have a free tier that might be sufficient for your needs.
o
Mailgun for the win! except the email is a bit funny
note the extra
"
on the top and bottom and the
\n
a
Well the extra quotes are in your code. So you kinda gotta expect 'em, right?

https://i2.paste.pics/ad9735d98631584664505012f26590fe.pngā–¾

o
I thought
"""
means long block of string? the
'\n
i didn't know if it auto returns strings
a
As are the explicit
\n
.
CFML has multi-line strings by default. there's no need for anything special.
o
I want
Copy code
multi
lines
here
a
Yes. Because it's HTML. HTML collapses whitespace
r
As Adam had inferred, emails come in two parts. A plain text, no formatting, part and a formatted HTML part.
a
Look at the source of that gist. The line breaks are there. You need to compose your strings for their intended purpose. The string in my gist was being used in HTML... whitespace collapses. That's how HTML works. You ought to know this. If your string is going to be used in a way that needs specific handling of line breaks, it depends on how they're handled as to what you need to do. In HTML: wrap the string in
<pre>
tags: https://trycf.com/gist/41ed805044512364e6006331d99b5a90/lucee5?theme=monokai In other situations you might need to put
\n
(or
\r\n
) depending on what's needed. Or maybe - like in markdown - implicit line breaks are respected. So using that example string I used in the first gist, if used as markdown, would render the line breaks just fine.
d
If you don't need formatting in the emails, send them as text, then what you see is what you get. Put returns and tabs and spaces where you want them, and not where you don't. If you do want html formatting, then the email content needs to be written as though it was html, because it is. Whitespace collapses, <br> mean line break, etc. However, different email clients (the program the user uses to read the message, not something you control) respect html formatting "differently". GMail in particular does whatever it thinks it "should", and is especially hard to control at a detailed level.