Part 4 - Send from a Tezos address
Make sure you have configured your application and authenticated the Mailchain SDK.
In this step you will receive a mail sent from a Tezos Protocol address.
Create sendFromTezos.js and paste the code below.
Update the from address with the Tezos Protocol address registered to your account.
// import Mailchain SDK
const { Mailchain } = require('@mailchain/sdk');
// import .env environment variables
require('dotenv').config();
// 24 word secret recovery phrase
const secretRecoveryPhrase = process.env.SECRET_RECOVERY_PHRASE;
// create a new instance of the Mailchain SDK with the secret recovery phrase
const mailchain = Mailchain.fromSecretRecoveryPhrase(secretRecoveryPhrase);
async function main() {
// get authenticated user
const user = await mailchain.user();
const result = await mailchain.sendMail({
// set `from` address to Tezos protocol address
from: '[email protected]',
// set `to` address to authenticated user address
to: [user.address],
subject: 'My first received Tezos mail',
content: {
text: 'Hello Tezos 👋',
html: '<p>Hello Tezos 👋</p>',
},
});
console.log(result);
}
main();
This code does the following:
- Authenticates the SDK.
- Gets current user's address.
- Set `from` address to your Tezos protocol address.
- Set `to` address to the authenticated user.
- Send mail.
In your terminal window run node sendFromTezos.js to run your application. You should see a message in your terminal window that looks similar to below (the `savedMessageId` will be different each time you send).
{
data: {
savedMessageId: '290a3a5328edc15384be74b82be6c0817700ab527a8fdb54ed1ad063768bb755',
sentMailDeliveryRequests: [ [Object] ]
}
}
This means the mail has been sent successfully, open Mailchain and check your inbox to see the new mail. The inbox contains different mailboxes, there will be one for your Tezos address. You will see the mail in this folder too. The sent folder also contains the mail you sent.