Quick Start
Get up and running with Metigan in 5 minutes. Send your first email in just a few simple steps. Perfect for developers who want to get started quickly.
1
Get Your API Key
First, you'll need an API key. You can create one in your Metigan Dashboard under Settings → API Keys.
Security Best Practice
Never commit your API key to version control. Always use environment variables to store your API keys securely.
2
Install the SDK
Install the Metigan SDK using your preferred package manager:
TerminalTerminal
1
2
3
4
5
6
7
8
# Using npm
npm install metigan
# Using yarn
yarn add metigan
# Using pnpm
pnpm add metigan3
Initialize the Client
Create a new Metigan client instance with your API key:
index.tsTypeScript
1
2
3
4
5
6
import Metigan from 'metigan';
// Initialize the Metigan client
const metigan = new Metigan({
apiKey: process.env.METIGAN_API_KEY || 'your_api_key_here'
});4
Send Your First Email
Now you're ready to send your first email! Choose between a simple email or using a template:
send-email.tsTypeScript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
async function sendWelcomeEmail() {
try {
const result = await metigan.email.sendEmail({
from: 'sender@example.com',
recipients: ['recipient@example.com'],
subject: 'Welcome to Metigan!',
content: '<h1>Welcome!</h1><p>This is your first email sent with Metigan.</p>'
});
if ('success' in result && result.success) {
console.log('✅ Email sent successfully!', result);
} else {
console.error('⌠Failed to send email:', result);
}
} catch (error) {
console.error('Error:', error);
}
}
sendWelcomeEmail();Complete Example
Here's a complete, production-ready example that includes error handling, type guards, and best practices:
complete-example.tsTypeScript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import Metigan from 'metigan';
import type { EmailApiResponse, EmailSuccessResponse } from 'metigan';
// Initialize the client
const metigan = new Metigan({
apiKey: process.env.METIGAN_API_KEY!
});
// Type guard helper for type safety
function isEmailSuccess(response: EmailApiResponse): response is EmailSuccessResponse {
return 'success' in response && response.success === true;
}
// Send email with proper error handling
async function sendEmail() {
try {
const result = await metigan.email.sendEmail({
from: 'Sender Name <sender@example.com>',
recipients: ['recipient@example.com'],
subject: 'Welcome to Metigan!',
content: `
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<h1>Welcome to Metigan!</h1>
<p>This is your first email sent with the Metigan SDK.</p>
</body>
</html>
`
});
if (isEmailSuccess(result)) {
console.log('✅ Email sent successfully!');
console.log('Tracking ID:', result.successfulEmails[0]?.trackingId);
console.log('Emails remaining:', result.emailsRemaining);
} else {
console.error('⌠Failed to send email:', result.message || result.error);
}
} catch (error) {
console.error('⌠Error sending email:', error);
}
}
// Run the function
sendEmail();What's Next?
Continue learning with these recommended resources