Unable to get SC8 to send email to new user

I have created a group based security module, with the “allow user’s to self register” and “Send email with link to reset password”. I start the app_Login and click the “New User” link and fill in the information. A new record is added to the SEC_USERS table but SC8 always crashes when it tries to send out the email with the activation code. I’ve used the same setting I use for my Thunderbird email (which work for Thunderbird) but SC’s send_mail_to_new_user(); always fails. Can some one give me the settings for a test email server that you know works, and the accompanying settings, so I can get this working, then maybe step-by-step change one setting at a time to change it back over to my own production settings. Here is the error message:
[TABLE=“class: scFormErrorTable, align: center”]
[TR]
[TD][/TD]
[TD=“class: scFormErrorTitle, align: left”] [TABLE=“width: 0”]
[TR]
[TD=“class: scFormErrorTitleFont”]ERROR[/TD]
[TD]Close[/TD]
[/TR]
[/TABLE]
[/TD]
[/TR]
[TR]
[TD=“class: scFormErrorMessage, align: center”]sprintf(): Too few arguments[/TD]
[/TR]
[/TABLE]

Fatal error: Uncaught exception ‘Swift_TransportException’ with message ‘Expected response code 250 but got code “501”, with message "501 HELO requires valid address "’ in C:\Program Files (x86)\NetMake\v81\wwwroot\scriptcase\prod hird\swift\classes\Swift\Transport\AbstractSmtpTransport.php:383 Stack trace: #0 C:\Program Files (x86)\NetMake\v81\wwwroot\scriptcase\prod hird\swift\classes\Swift\Transport\AbstractSmtpTransport.php(281): Swift_Transport_AbstractSmtpTransport->_assertResponseCode(‘501 HELO requir…’, Array) #1 C:\Program Files (x86)\NetMake\v81\wwwroot\scriptcase\prod hird\swift\classes\Swift\Transport\EsmtpTransport.php(269): Swift_Transport_AbstractSmtpTransport->executeCommand(‘HELO [fe80::914…’, Array, Array) #2 C:\Program Files (x86)\NetMake\v81\wwwroot\scriptcase\prod hird\swift\classes\Swift\Transport\AbstractSmtpTransport.php(297): Swift_Transport_EsmtpTransport->executeCommand(‘HELO [fe80::914…’, Array) #3 C:\Program Files (x86)\NetMake\v81\wwwroot\scriptcase\prod hird\swift\classes\Swift\T in C:\Program Files (x86)\NetMake\v81\wwwroot\scriptcase\prod hird\swift\classes\Swift\Transport\AbstractSmtpTransport.php on line 383

This code is working for me in SC 8. I have created a PHP method in which this code resides. In my application, I have a PHP button defined which calls this method. Hope it helps.
// Send email

$mail_smtp_server          = 'mail.emailserver.com';        // SMTP server name or IP address.  In my situation, the server resides at a different domain than my domain.
$mail_smtp_user            = 'user@domain.com';            // SMTP user name which has credentials to send email at emailserver.com.
$mail_smtp_pass            = 'password';                        // SMTP password
$mail_from                 = 'admin@domain.com';            // From email
$mail_to                   = 'recipient@theirdomain.com;   // To email
$mail_message              = 'Message goes here.';
$mail_subject              = 'Test Email';
$mail_format               = 'H';                          // Message format: (T)ext or (H)tml
$mail_cc                     = '';

try {
sc_mail_send($mail_smtp_server,
$mail_smtp_user,
$mail_smtp_pass,
$mail_from,
$mail_to,
$mail_subject,
$mail_message,
$mail_format,
$mail_cc,’’, ‘465’, ‘S’,’’);
// Note: 465 and S are for TLS which my email server requires. If yours does not, you could try using ‘’ for each parameter instead.
// Write status message indicating success
}

//catch exception
catch(Exception $e) {
// Write status message indicating failure
// Uncomment next line to see error message of failure
//echo 'Message: ’ .$e->getMessage();
}

Thank you bradk. I will give this a try. Even if it works, I’m not sure it will help with the failure of the send_mail_to_new_user() command, which is what the security module generates as code. The automatically generated code doesn’t inlcude any of the parameters needed by the sc_mail_send() command. Here is the only code I can find, that was auto-generated by the “Security Module” generator, that has to do with sending an email to a new user. It’s in the app_form_add_users.onAfterInsert event:

// Note that no variables are set here. I’m assuming that the send_mail_to_new_user() command is pulling what it needs from SC8’s Options/Settings “SMTP” settings.

send_mail_to_new_user();

sc_commit_trans();
sc_redir(‘app_Login’);

Go into the application app_form_add_users. Open the Programming Tab | PHP Methods. You will see send_mail_to_new_user. Go inside that section and you will see at the bottom what I posted without the try/catch loop. Try defining the parameters as suggested and you should be good to go. I don’t remember if the defaults worked. That may have been the reason I decided to define the parameters.

I have created the button and coded it as shown in your first response. The error message has changed, which I guess is a good thing in a way. I’m using my Thunderbird email client as a guide and for this outgoing server the “Connection Security” is set to STARTTLS. The sc_mail_send()'s encryption setting is either S or N, for SSL or None. Is there a separate unpublished setting for STARTTLS? Here is the error message I’m getting now:

[TABLE=“class: scFormErrorTable, align: center, width: 320, height: 30”]
[TR]
[TD=“class: scFormErrorTitle, align: left”] [TABLE=“width: 0”]
[TR]
[TD=“class: scFormErrorTitleFont”]ERROR[/TD]
[TD]Close[/TD]
[/TR]
[/TABLE]
[/TD]
[/TR]
[TR]
[TD=“class: scFormErrorMessage, align: center”]stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages:error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol
stream_socket_client(): Failed to enable crypto
stream_socket_client(): unable to connect to ssl://smtp.telus.net:587 (Unknown error)[/TD]
[/TR]
[/TABLE]

Try port 465. See if that works instead of 587.

WHAT SORCERY IS THIS!.. Ha ha ha ha h…k, it worked. Thank you Brad! I can now move on with my life.

I assume that is a good thing:) Happy coding!

Hi,

I had the same error but, work well when the app is deployed, in devel mode, the macro to send email of SC, it does not work, is like can not negotiate the SSL transaction with Google.

AYMG

Try using telnet from your development machine: telnet | open smtp.gmail.com 587

You should see something like this in response: 220 smtp.gmail.com ESMTP y36sm4733560qtc.46 - gsmtp

If not, you may have a firewall issue. You can also try port 465 to see if the result is any different.