I am using Rails 3.2.5 and exception_notification gem. In production mode, I am generally sending emails using PostMarkApp's postmark-rails gem.
Initially, I got a View error from exception_notification gem stating
ActionView::Template::Error (code converter not found (UTF-8 to UTF-16))
so based on exception_notification gem raises ActionView::Template::Error (code converter not found (UTF-8 to UTF-16)) only on Heroku production mode, I moved to
gem 'exception_notification', git: 'git://github.com/alanjds/exception_notification.git'
This solved that bug. Now, I want the gem to send emails from my gmail account instead of using PostMarkApp credits, so I added the following to my production.rb, yet Exception Notification attempts to send email only from Post Mark App. Why is this setting not working?
config.middleware.use ExceptionNotifier,
sender_address: 'noreply#mydomain.com',
exception_recipients: 'myemail#mydomain.com',
sections: %w{current_user} + ExceptionNotifier::Notifier.default_sections,
ignore_crawlers: %w{Googlebot bingbot},
email_format: true,
normalize_subject: true,
smtp_settings: {
:address => "smtp.gmail.com",
:port => "587",
:domain => "www.gmail.com",
:user_name => "myemail#gmail.com",
:password => "mypassword",
:authentication => "plain",
:enable_starttls_auto => true,
:openssl_verify_mode => 'none'
}
config.action_mailer.delivery_method = :postmark
config.action_mailer.postmark_settings = { :api_key => "_____" }
For some reason it appears that SMTP delivery does NOT work in the development environment. I tried a number of different settings and was never able to get this to work. It DOES however work in my other environments. Older posts seem to indicate this as well:
http://www.ruby-forum.com/topic/64776
http://www.devchix.com/2008/12/09/how-to-see-exception_notification-plugin-work-in-development-mode/
In development, I am using the following in my development.rb:
config.action_mailer.delivery_method = :letter_opener
config.middleware.use ExceptionNotifier,
:sender_address => 'test#test.com',
:exception_recipients => 'recipient#test.com'
In my "staging" environment, I am using the following in my staging.rb:
config.action_mailer.delivery_method = :smtp
config.middleware.use ExceptionNotifier,
:sender_address => 'test#test.com',
:exception_recipients => 'recipient#test.com'
The staging.rb acquires it's SMTP settings from an initializer I have the uses SendGrid for SMTP:
ActionMailer::Base.smtp_settings = {
:address => "smtp.sendgrid.net",
:port => 25,
:domain => "test.com",
:user_name => "user_name",
:password => "password",
:authentication => "plain"
}
Try the suggestion at http://www.scottw.com/multiple-smtp-servers-with-action-mailer
or at Rails ActionMailer with multiple SMTP servers
Related
I cannot send emails out in Yii2-usuario, e.g. when a password recovery is requested. Email is not working at all.
There is just a flash message saying
Unable to send recovery message to the user
I think that this is a transport problem. There are tons of things that can go wrong here: firewall issues, tls-/security-settings, self-signed certificates, wrong ports, hostname-typos, ...
How to debug transport layer? How to enable debugging to trace connection to the email service?
Found the error. In config/web.php the mailer was configured as:
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'useFileTransport' => false,
'viewPath' => '#app/mail',
'htmlLayout' => 'layouts/main-html',
'textLayout' => 'layouts/main-text',
instead of
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'useFileTransport' => false,
'viewPath' => '#app/mail',
'htmlLayout' => '#app/mail/layouts/main-html',
'textLayout' => '#app/mail/layouts/main-text',
The layout paths were wrong. So the Mailer could not render the messages and failed sending out emails since Yii2-usuario uses formatted emails.
Everything works now.
I have the following smtp configuration, but I'm not sure since sometimes I face ssl timed out while sending an email.
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'viewPath' => '#common/mail',
'useFileTransport' => true,
],
'mail' => [
'class' => 'yii\swiftmailer\Mailer',
'viewPath' => '#backend/mail',
'useFileTransport' => false,//set this property to false to send mails to real email addresses
//comment the following array to send mail using php's mail function
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'in-v3.mailjet.com',
'username' => 'a3027c3xxx',
'password' => 'c838779xxx',
'port' => '465',
'encryption' => 'ssl',
],
],
Then I use like this
$message = Yii::$app->mail->compose();
$message->setTo(Yii::$app->params['adminEmail'])
->setFrom(Yii::$app->params['adminEmail'])
->setTo("mymail#gmail.com")
->setSubject('Password Reset')
->setHtmlBody($this->renderAjax('//email/_konten',['hello'=>"To black" ,'konten'=>'this is konten','link'=>Yii::$app->params['baseurl'].'lupapass/chpass?&q=empty','textbutton'=>'Click this link']))
->send();
and the result is sometime I face timed out.
But if I send directly from swiftmailler class like below code it sucessfully send 100 email without any ssl timed out
$transport = \Swift_SmtpTransport::newInstance('in-v3.mailjet.com', 465)
->setUsername('myusername')
->setPassword('s3cr3t')
->setEncryption('ssl');
$mailer = \Swift_Mailer::newInstance($transport);
$message = \Swift_Message::newInstance('Password Reset')
->setFrom(array('no-reply#myweb.com' => 'My Web'))
->setTo(array('some#one.com'))
->setBody($this->renderAjax('//email/_konten',['hello'=>"To black" ,'konten'=>'this is konten','link'=>Yii::$app->params['baseurl'].'lupapass/chpass?&q=empty','textbutton'=>'Click this link']))
->setContentType("text/html")
;
$result = $mailer->send($message);
If you ask how my ssl timed out here is my question link
How to solve Swift_TransportException Connection to ssl Timed Out error?
So I start thinking is this ssl timed out because my configuration? or different sending method? from first example and second example?
in common\config\main-local.php there is a mailer => [] and mail => [] is this neccessary?
an can you please explain what is useFileTransport really?
Thanks in advance.
PS. I have already use any thirdparty and port configuration but still facing ssl timed out issue.
According to Gmail SMTP config when you are using encryption ssl or tls use port 587 instead of 465
I created a basic laravel passport authentication and created callback and redirect to authorize user below is my code
Route::get('/redirect', function () {
$query = http_build_query([
'client_id' => 4,
'redirect_uri' => 'http://localhost:8000/callback',
'response_type' => 'code',
'scope' => '',
]);
return redirect('http://localhost:8000/oauth/authorize?'.$query);
});
Route::get('/callback', function (Request $request) {
$http = new GuzzleHttp\Client;
$response = $http->post('http://localhost:8000/oauth/token', [
'form_params' => [
'grant_type' => 'authorization_code',
'client_id' => 4,
'client_secret' => 'MUqUFrtAx3ix84zFTxwqQXA5PQDY7SWwVFW9tCNX',
'redirect_uri' => 'http://localhost:8000/callback',
'code' => $request->code,
],
]);
return json_decode((string) $response->getBody(), true);
});
I followed the steps provided on https://laravel.com/docs/5.4/passport but when i click on authorize button the page keeps loading without any response and i have to restart artisan serve. What could be the possible issue?
The issue is when using php artisan serve, it uses a PHP server which is single-threaded.
The web server runs only one single-threaded process, so PHP applications will stall if a request is blocked.
You can do this solution:
When making calls to itself the thread blocked waiting for its own reply. The solution is to either seperate the providing application and consuming application into their own instance or to run it on a multi-threaded webserver such as Apache or nginx.
Or if you are looking for a quick fix to test your updates - you can get this done by opening up two command prompts. The first would be running php artisan serve (locally my default port is 8000 and you would be running your site on http://localhost:8000). The second would run php artisan serve --port 8001.
Then you would update your post request to:
$response = $http->post('http://localhost:8001/oauth/token', [
'form_params' => [
'grant_type' => 'authorization_code',
'client_id' => 4,
'client_secret' => 'MUqUFrtAx3ix84zFTxwqQXA5PQDY7SWwVFW9tCNX',
'redirect_uri' => 'http://localhost:8000/callback',
'code' => $request->code,
],
]);
This should help during your testing until you are able to everything on server or a local virtual host.
In your /redirect route you are providing same localhost:8000 . change your redirect_uri and same mistake in callback route .
Change Your
'redirect_uri' => 'http://localhost:8000/callback',
To
'redirect_uri' => 'http://localhost:8001/callback',
Note: Im running other project on port 8001 .you can change it with yours :)
try to use XAMPP or another web server instead of just php artisan serve
I am trying to set up a MediaWiki site at work. I want it to be resilient across multiple sites, so what I am planning is 1 master database to take writes, and then a local slave database for each web install. This will mean I will have:
Server 1: MySQL Master
Server 2: MySQL Slave, Apache + MW
Server 3: MySQL Slave, Apache + MW
...
Server N: MySQL Slave, Apache + MW
What I want to happen, is if a site "goes dark", they will still have a local copy of the MW running in Read-Only mode, until it is able to contact the Master MySQL server again. I have set up the below configuration file on 1 of the slave hosts, which works fine. However, once I turn off the Master MySQL server to simulate a loss of connection, MW comes up with a DB error instead of just becoming Read-Only.
$wgDBservers = array(
array('host' => "10.10.10.10",
'dbname' => "db",
'user' => "####",
'password' => "####",
'type' => "mysql",
'flags' => DBO_DEFAULT,
'load' => 0),
array('host' => "localhost",
'dbname' => "db",
'user' => "####",
'password' => "####",
'type' => "mysql",
'flags' => DBO_DEFAULT,
'load' => 1)
);
Have I missed something from the configuration and this is something that I am able to do, or does it not work because it is not intended to work that way? Any help is appreciated.
This is not in any way "best practice" but in lieu of any other answer, I am posting it for anyone needing a quick work-around.
It is a PHP script that sits directly in the LocalSettings.php file and checks the status of the Master Database. The "proper" way to do it would probably be with an extension, but I don't have time to learn how to make one. You need to ensure that the user account that you are using to connect to MySQL, has Read-Only access to the slave database.
$wgDBSite_Master = array('host' => "<master ip>", 'dbname' => "<database>", 'user' => "<user>", 'password' => "<pass>", 'type' => "mysql", 'flags' => DBO_DEFAULT, 'load' => 0);
$Site_MasterTest = mysql_connect($wgDBSite_Master['host'], $wgDBSite_Master['user'], $wgDBSite_Master['password']);
if (!$Site_MasterTest) {
$wgReadOnly = 'Wiki failed to contact the Master server. Your site is currently running Dark. No edits will be saved.<br>Last Error: '.mysql_error();
$wgSiteNotice = $wgReadOnly;
$wgDBservers = array();
}
else {
$wgSiteNotice = 'Everything running normally, Captain';
$wgDBservers = array( $wgDBSite_Master );
}
$wgDBservers[] = array('host' => "localhost", 'dbname' => "<database>", 'user' => '<user>', 'password' => "<pass>", 'type' => "mysql", 'flags' => DBO_DEFAULT, 'load' => 1);
all:
I am testing unixODBC in Solaris 10 environments, and find if libodbc and MyODBC driver are dynamically linked with libltdl.so:
ldd /usr/lib/libodbc.so.2
libltdl.so.7 => /usr/local/lib/libltdl.so.7
libiconv.so.2 => /usr/local/lib/libiconv.so.2
libthread.so.1 => /usr/lib/libthread.so.1
libc.so.1 => /usr/lib/libc.so.1
libgcc_s.so.1 => /usr/lib/libgcc_s.so.1
libm.so.2 => /usr/lib/libm.so.2
/platform/SUNW,Sun-Fire-V240/lib/libc_psr.so.1
ldd /data/nan/mysql-connector-odbc-5.2.4-src/lib/libmyodbc5a.so
libodbc.so.2 => /usr/lib/libodbc.so.2
libthread.so.1 => /usr/lib/libthread.so.1
libm.so.2 => /usr/lib/libm.so.2
libodbcinst.so.2 => /usr/lib/libodbcinst.so.2
libgcc_s.so.1 => /usr/lib/libgcc_s.so.1
libltdl.so.7 => /usr/local/lib/libltdl.so.7
libiconv.so.2 => /usr/local/lib/libiconv.so.2
libc.so.1 => /usr/lib/libc.so.1
/platform/SUNW,Sun-Fire-V240/lib/libc_psr.so.1
sometimes it will connect MySQL server failed when starting up application. The log likes this:
[ODBC][6738][1361325895.588941][SQLConnect.c][1111]Can't open lib '/data/nan/mysql-connector-odbc-5.2.4-src/lib/libmyodbc5a.so' : file not found
[ODBC][6738][1361325895.588979][SQLConnect.c][1111]Can't open lib '/data/nan/mysql-connector-odbc-5.2.4-src/lib/libmyodbc5a.so' : file not found
After a while, the application runs OK.
But if libodbc and MyODBC driver aren't dynamically linked with libltdl.so:
ldd /usr/local/lib/libodbc.so.2
libiconv.so.2 => /usr/local/lib/libiconv.so.2
libthread.so.1 => /usr/lib/libthread.so.1
libc.so.1 => /usr/lib/libc.so.1
libgcc_s.so.1 => /usr/local/lib/libgcc_s.so.1
libm.so.2 => /usr/lib/libm.so.2
/platform/SUNW,UltraAX-i2/lib/libc_psr.so.1
ldd /data1/susie/mysql/tools/test_static_modify/mysql-connector-odbc-5.2.3-src/lib/libmyodbc5a.so
libodbc.so.2 => /usr/local/lib/libodbc.so.2
libthread.so.1 => /usr/lib/libthread.so.1
libm.so.2 => /usr/lib/libm.so.2
libodbcinst.so.2 => /usr/local/lib/libodbcinst.so.2
libgcc_s.so.1 => /usr/local/lib/libgcc_s.so.1
libiconv.so.2 => /usr/local/lib/libiconv.so.2
libc.so.1 => /usr/lib/libc.so.1
/platform/SUNW,UltraAX-i2/lib/libc_psr.so.1
The application runs always OK..
So I think it may be a potential issue in unixODBC. Could anyone help to check it? Thanks very much in advance!
Best Regards
Nan Xiao
All unixODBC does is call dlopen and dlsym from libltdl, I wonder if there is some statics in the lib that is causing the problem. If you don't build unixODBC to use a exernal libltdl it uses its own version (from libtool), so again, it may be a conflict with them both hitting the same lib. You say you are using Solaris. Is the libltdl you are linking with from Sun?
What might be interesting is if you can get it to fail under truss so we could see just what the "file not found" is caused by.
I also wonder just what the MySQL driver uses libltdl for?