How to specify a non global from name when sending mail in laravel 7.x - laravel-7

I'm using laravel 7.x with mailgun running on my local environment and everything seems to be running fine. I want to be able to set the from "name" when sending individual emails.
In Laravel 7.x documentation on "Configuring The Sender" they explain how to send an email and specify a "from address", but do not show how to set a name.
return $this->from('example#example.com')
->view('emails.orders.shipped');
They also specify how to set a global from address with the name set
'from' => ['address' => 'example#example.com', 'name' => 'App Name'],
I want to be able to send an email where I can set multiple names depending on which part of the application I'm sending from. (e.g. password reset would be different from a usage notification)
What does not work
The example below returns Swift_RfcComplianceException: Address in mailbox given [Test User <example#example.com>] does not comply with RFC 2822, 3.6.2
return $this->from('Test User <example#example.com>')
->view('emails.orders.shipped');
I also tried using the array syntax from the global method, but this didn't seem to have any impact on the name itself.
return $this->from([
'address' => 'example#example.com',
'name' => 'Test User'
])
->view('emails.orders.shipped');
Is it possible to set the name using this method?

You should use this syntax:
$this->from('example#example.com','Example')->view('emails.orders.shipped');
I could not find the proper documentation for this, but similar syntax was used in laravel emails.

Related

Strapi: how to set disabled as default a new user registered, then enable by an administrator

how can I set "disabled user" as default configuration to any new user which register on, then send to any administrator an email saying "new user!!" and the administrator could anable the new user and send to him an email to let him know was approved
You will have to customize the register function.
To do so, you will have to use the extensions folder.
See the documentation here: https://strapi.io/documentation/3.0.0-beta.x/concepts/concepts.html#extensions
Here is the register function you will have to update: https://github.com/strapi/strapi/blob/master/packages/strapi-plugin-users-permissions/controllers/Auth.js#L358
You will have to create ./extensions/users-permissions/controllers/Auth.js file that contains a module.exports with only the register function inside. Copy the plugin's one and paste it in the extension file we just created.
Then in you extend register function, you will have to update the params object and set the blocked key to true.
Just after this line https://github.com/strapi/strapi/blob/master/packages/strapi-plugin-users-permissions/controllers/Auth.js#L378.
Then if you want to send an email, you can use the email plugin that provides you a way to send emails.
Here is the example of how we send confirmation email: https://github.com/strapi/strapi/blob/master/packages/strapi-plugin-users-permissions/controllers/Auth.js#L508
Copy this line and update values to send an email to yourself with the content you want.

I want to send email attachment using nodemailer in node js.i am using elasticemail gate way

I need to send a URL attachment in nodemailer.i try to many ways but mail was not deliverd.I was seen elasticemail gateway they showed a error like this "suppressed" how will i solve this issue
attachments:[{ // use URL as an attachment
filename:'GSTR3B_33ADQFS8223E1ZY_012019_1551501263.pdf',
path:'my url'}]
if you are getting "suppressed" from Elastic Email check in the Contacts section on your dashboard to be sure that the contact is in an "Active" state. The contact might be suppressed by the system.

Docusign ReplyEmailAddressOverride setting, does it require a ReplyNameOverride as well?

If you use the properties in EmailSettings to change the reply email address, do you also need to assign a value to the reply name override property? If you don't, what does it use for the name?
From the legacy official REST documentation, the replyEmailNameOverride is NOT required.
While the documentation doesn't mention this, if you don't specify it, it seems that it will reuse the name of the original recipient it was sent to.
See my example below in C#:
EmailSettings settings = new EmailSettings
{
ReplyEmailAddressOverride = "otherUserThanTheSende#fakeemail.com"
};
docuSignEnvelope.EmailSettings = settings;
To go further, if you look at the DocuSign recipient email source, you can see that they assign the recipient name to the reply email as below :

REST API Endpoint for changing email with multi-step procedure and changing password

I need help for creating the REST endpoints. There are couple of activities :
To change the email there are 3 URL requests required:
/changeemail : Here one time password (OTP) is sent to the user's mobile
/users/email : the user sends the one time password from previous step and system sends the email to the new user to click on the email activate link
/activateemail : user clicks on the link in the new email inbox and server updates the new email
To change password :
/users/password (PATCH) : user submits old password and new password and system accordingly updates the new password
Similarly, there are other endpoints to change profile (field include bday, firstname and last name)
after reading online I believe my system as only users as the resource --> so to update the attributes I was thinking of using a single PATCH for change email and change password and along with that something like operation field so the above two features will look like :
For changing email :
operation : 'sendOTPForEmailChange'
operation : 'sendEmailActivationLink'
operation : 'activateEmail'
For changing password :
operation : 'changePassword'
and I will have only one endpoint for all the above operations that is (in nodejs) :
app.patch('/users', function (req, res) {
// depending upon the operation I delegate it to the respective method
if (req.body.operation === 'sendOTPForEmailChange') {
callMethodA();
} else if (req.body.operation === 'sendEmailActivationLink') {
callMethodB();
} else if (req.body.operation === 'activateEmail') {
callMethodC();
} else if (req.body.operation === 'changePassword') {
callMethodC();
} else sendReplyError();
});
Does this sound a good idea ? If not, someone can help me form the endpoints for changeemail and changepassword.
Answer :
I finally settled for using PATCH with operation field in the HTTP Request Body to indicate what operation has to be performed.
Since I was only modifying a single field of the resource I used the PATCH method.
Also, I wanted to avoid using Verbs in the URI so using 'operation' field looked better.
Some references I used in making this decision :
Wilts answer link here
Mark Nottingham' blog link article
and finally JSON MERGE PATCH link RFC
You should make the links that define the particular resource, avoid using PATCH and adding all the logic in one link keep things simple and use separation of concern in the API
like this
1- /users/otp with HTTP Verb: GET -> to get OTP for any perpose
2- /users/password/otp with HTTP Verb: POST -> to verify OTP for password and sending link via email
3- /users/activate with HTTP Verb: POST to activate the user
4- /users/password with HTTP Verb: PUT to update users password
Hashing Security is a must read, IMHO, should you ever want to implement your own user account system.
Two-factor identification should always be considered, at least as an opt-in feature. How would you integrate it into your login scheme ?
What about identity federation ? Can your user leverage their social accounts to use your app ?
A quick look at Google yielded this and this, as well as this.
Unless you have an excellent reason to do it yourself, I'd spend time integrating a solution that is backed by a strong community for the utility aspects of the project, and focus my time on implementing the business value for your customers.
NB: my text was too long for the comments
Mostly agree with Ghulam's reply, separation of concerns is key. I suggest slightly different endpoints as following:
1. POST /users/otp -> as we are creating a new OTP which should be returned with 200 response.
2. POST /users/email -> to link new email, request to include OTP for verification.
3. PUT /users/email -> to activate the email.
4. PUT /users/password -> to update users password.

Get build requestor using Groovy script (Jenkins / email-ext)

I want to get the username and/or email address of the build requestor in a post-build script.
Sidenote: I want the requestor so I can set the email sender of the post-build email notification dynamically in the email-ext plugin's pre-send script.
AbstractBuild has built-in support for AbstractBuild.getCulprits() and AbstractBuild.hasParticipant(User user) but I can't find a method for retrieving the requestor. I can't find any useful reference in reference list to the User class either.
I managed to solve it via the Cause of the the build, as recommended in this answer.
The reason that the build requestor can be found in the cause for a build makes perfect sense when you think about it: Not every build is directly triggered by a user.
If it is triggered by a user, the list of causes for the build contains a Cause.UserIdCause, with the user's id and name.
This code snippet worked for me. It extracts the username from the build via the cause and sets the From and ReplyTo headers. I use it in the pre-send script of the email-ext Jenkins plugin.
import javax.mail.internet.InternetAddress
cause = build.getCause(hudson.model.Cause.UserIdCause.class);
username = cause.getUserName()
id = cause.getUserId()
email = new InternetAddress(String.format("%s <%s#example.com>", username, id))
msg.setFrom(email)
msg.setReplyTo(email);

Resources