Translate email messages - ruby-on-rails-4

I would like to translate email messages. I have a method in my model which is called after_save. This method creates mailer:
MyMailer.delay.notify_on_new_object self
The mailer uses mail message to send it:
mail(to: #email, subject: t(:subject, scope: "mailers.object"))
The problem is that every time english version of email is sent. No matter which locale is set in request. I know that request informations are not passed to models. So how can I set proper locale from request before sending email?

Have you tried something like:
I18n.locale = :es # or a locale variable given to the mailer
mail(to: #email, subject: t(:subject, scope: "mailers.object"))

Related

spring lemon - "Request method 'GET' not supported" on email verification

I am trying to use spring lemon for user handling. I am sending a registration request which gets a 201 response and sends an email to the user, but when the user clicks the link he gets a "Request method 'GET' not supported" response. I looked at the spring lemon code, and in LemonController.java line 104 the verifyUser method uses a #PostMapping annotation. Shouldn't it use a GET annotation? The link from the email creates a GET request, not POST.
Thanks.

Designing URLs without verbs for operations related to user in a REST API

I'm building REST API.
I have following structure
GET /user/{id} - get
POST /users - Create user
PUT /users/{id} - Update user
DELETE /users/{id} - Delete user
The problem is following. As I got from many tutorials/articles - it is bad practice to use action in URL. But what to do with such actions like:
check email (is unique)
recover user by email
?
Assume user registration. User submits form ( POST /users ) and I need to check if email is unique. Do I need to do it in same api method and return validation errors as response body?
Or do I need to create something like
POST /users/email
And what about user recovering by email? Where do I need to do it? Because recover is verb
POST /users/recover
I'm not sure, that I'm doing it right and I can't find correct explanation for that situation.
Validating the e-mail and registering the user
If you want, you can have an endpoint to check whether an e-mail is already registered or not. It's up to your requirements. So, you can have something as following and then send the e-mail which will be validated in the request payload:
POST /users/email/validation
{
"email": "mail#example.com"
}
The endpoint above can be invoke, for example, when the user completes the e-mail field of your account registration form.
However, do not forget checking if the e-mail is already registered when creating a user:
POST /users
{
"firstName": "John",
"lastName": "Doe",
"email": "mail#example.com",
"password": "123456"
}
If an e-mail is already registered, you could consider returning a 409 Conflict status code and a payload that includes enough information for a user to recognize the source of the conflict.
Recovering the password
I'm unsure if this is your requirement, because of this I posted a comment asking for clarification. I presume you are trying to recover the password of a user, assuming the user has no more access to their account.
If so, you could have an endpoint as following and then send the e-mail of the user in the request payload:
POST /users/password/recovery
{
"email": "mail#example.com"
}
Then your server can send a link with a token to the e-mail specified in the payload. Only send the e-mail if the e-mail specified in the payload is registered in your application, of course.
The link should take the user to a page where they will enter the new password and, when submitting, an endpoint to replace the password of the user will be invoked, sending the token and the new password to the server:
PUT /users/password?token=SomeValueGoesHere
{
"password": "654321"
}

How I can parse email to get original recipient of an email?

I had email source with me and want parse original recipient of email.
Lets say "user1#test.com" is receiving a email, but in "To" list user1#test.com, user2#test.com & user3#test.com are mentioned. I want to get only user1 from email source.
In initial analysis, email from mdeamon server contains "X-MDaemon-Deliver-To:" tag. Similarly email from Devcot mail server contains "Delivered-To:". But not getting generic parsing logic to get original email recipient.
How I can parse email to get original recipient of an email?
The best way to get this information is probably to parse the Received headers to see who the message was delivered for. In other words, look for a Received header that has a for token followed by x#x.com (where x#x.com will be the recipient).

Redirect users to their specified email accounts with receiver and message fields pre-filled

I have an email address "myaddress#gmail.com". I have created a django form that has a text field and a button. I want to redirect anyone who types a message in the text box to their respective emails so that they can send the message they typed to "my address". This means that as they log in to their email accounts, their message boxes should already be filled with the message they typed and the receiver field should already have "myaddress#gmail.com". The problem is how to redirect the users to their email accounts and prefill the specified fields.
Can anyone help me please?
If the user has set a default email program, most of them will be triggered on mailto:. I know gmail works with mailto: as well, and its possible that other web email services might. All desktop email clients - again only if it is set as the default email program will work on mailto:
The format is:
mailto:[emailaddress]?header=value&header1=value1....&headerN=valueN
Here is an example that sets the subject of the email automatically:
Email me

How to get the sending user's id from the callback page with fb-request-form?

im sending invitation requests via the request-form to my application and i want to the sending users id from the action page. i can successfully get the ids the invitations are sent to but am not sure how to get the senders id.
im using php. this is part of my callback page:
if (isset($_REQUEST['ids'])){
$amount = sizeof($_REQUEST['ids']);
print_r($_REQUEST);
echo "<br>$amount invitations Successfully Sent";
}
the request prints out like this:
Array ( [mfs_typeahead_req_form_4cf74f96db3688507476560] => Start Typing a Name [ids] => Array ( [0] => 510149460 ) [fbs_258181898823] => \"access_token=258181898823|2.q_qb_yoReO0_xc4H8PxKRQ__.3600.1291280400-100000664203700|LqtGr_OiJTASGmek61awxmxfvFk&expires=1291280400&secret=85eTEELZj8lkV82V_PwRSA__&session_key=2.q_qb_yoReO0_xc4H8PxKRQ__.3600.1291280400-100000664203700&sig=d4cc0e4c0992ea29c0adfd60dc27185b&uid=100000664203700\" )
the id i want is 100000664203700
If using requets 2.0 http://developers.facebook.com/docs/reference/dialogs/requests/
You can get the user id form current session and append to the data parameter in the request. Facebook will send the data though as a string and you can extract on the redirect uri.
as per your print_r() Have you tried json decoding the $_REQUEST? This will give you an array to work with and you can do a quick search for uid= in your string.
http://php.net/manual/en/function.json-decode.php