How to use send Email To Friend GraphQL mutation Magento 2?

Send Email to Friend GraphQL Mutation used to send emails to a specific recipient with product details and your message.

By Default Email to Friend Setting is disabled and you want to try to run mutation, the response will throw an error,  “Email to a Friend” is not enabled.

For functionality to works well, You must activate settings from the admin configuration,
Stores > Configuration > Catalog > Email to a friend > Enabled Yes
Save Config.

GraphQL Mutation,

mutation {
  sendEmailToFriend(
    input: {
      product_id: 2
      sender: {
        name: "Rakesh"
        email: "rbjesadiya@rakeshjesadiya.com"
        message: "I will just sending you a product"
      }
      recipients: [
        { name: "Vijay", email: "test@yourfrineddemail.io" }
        { name: "Test", email: "rbj@testtest.com" }
      ]
    }
  ) {
    sender {
      message
      name
    }
    recipients {
      name
    }
  }
}
  • product_id attribute used the real product id you want to display in the mail. Its a mandatory to defined the mutation.
  • sender attribute field will be your name and email of the sender, the message is the text you want to send in the mail. All the fields are mandatory as defined in the mutation.
  • recipients attribute used to send email to a friend, you can send single or multiple emails in the attribute.
    name and email of the recipient must be mandatory.