Skip to content

Commit a97f2c6

Browse files
authored
Update email quickstart
1 parent 673db2e commit a97f2c6

File tree

1 file changed

+57
-27
lines changed

1 file changed

+57
-27
lines changed

email.md

Lines changed: 57 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,44 @@
11
## Quickstart
22

3-
#### Initialize the client with configuration
4-
5-
We support multiple authentication methods, e.g. you can use [API Key Header](https://www.infobip.com/docs/essentials/api-authentication#api-key-header). In this case value for `ApiKeyPrefix` in example below will be `App`.
6-
7-
To see your base URL, log in to the [Infobip API Resource](https://www.infobip.com/docs/api) hub with your Infobip credentials.
3+
### Prepare configuration
84

5+
First step is to initialize `Configuration` object to handle API authentication. In this case value for `ApiKeyPrefix` in example below will be `App`.
96
```csharp
107
var configuration = new Configuration()
118
{
12-
BasePath = "<set your base URL here>",
13-
ApiKeyPrefix = "<set API key prefix here (App/Basic/IBSSO/Bearer)>",
14-
ApiKey = "<set your API key here>"
9+
BasePath = "<put your base URL here>",
10+
ApiKeyPrefix = "<put API key prefix here (App/Basic/IBSSO/Bearer)>",
11+
ApiKey = "<put your API key here>"
1512
};
16-
17-
SendEmailApi sendEmailApi = new SendEmailApi(configuration);
1813
```
1914

20-
Before sending email messages you need to verify the domain with which you will be sending emails.
15+
Now we can initialize Email API client.
16+
```csharp
17+
var sendEmailApi = new SendEmailApi(configuration);
18+
```
2119

22-
#### Send Email with file attachment
20+
#### Send email
21+
We're now ready for sending our first email. Note that response contains `BulkId` property which may be useful for checking the status sent emails.
2322
Fields `from`, `to` and `subject` are required, also the message must contain at least one of these: `text`, `html` or `templateId`.
2423

2524
IMPORTANT NOTE:
25+
Keep in mind folowing restrictions while using trial account
26+
- you can only send messages to verified email addresses
27+
- you can only use your emails addres with Infobip test domain in following form `YourUserName@selfserviceib.com`
28+
29+
```csharp
30+
string mailTo = "john.doe@company.com";
31+
string mailFrom = "<set your user name>@selfserviceib.com";
32+
string mailText = "This is my first email.";
33+
34+
var response = sendEmailApi.SendEmail(from: mailFrom, to: mailTo, subject: subject, cc: null, bcc: null, text: mailText);
35+
36+
string bulkId = response.BulkId;
37+
```
38+
39+
#### Send Email with file attachment
2640

27-
If you are using Infobip free trial account you can only send messages to registered email.
28-
Also make sure that from parameter is set to YourUserName@selfserviceib.com.
41+
Example below shows how to send email with attachment.
2942

3043
```csharp
3144
try
@@ -35,13 +48,37 @@ Also make sure that from parameter is set to YourUserName@selfserviceib.com.
3548

3649
EmailSendResponse sendResponse = sendEmailApi.SendEmail(
3750
"<set your user name>@selfserviceib.com",
38-
"<set your test mail>@<test mail>.com",
51+
"<set your test mail>@<verified email>.com",
3952
"Mail subject text",
40-
text:"Test message with file 2",
41-
attachment:attachmentFile
42-
);
53+
text:"Test message with file",
54+
attachment:attachmentFile);
4355

44-
attachmentFile.Dispose();
56+
attachmentFile.Dispose();
57+
}
58+
catch (Exception ex)
59+
{
60+
// HANDLE EXCEPTION
61+
}
62+
```
63+
64+
#### Schedule Email for later sending
65+
66+
You can also send delayed emails very easily. All you need to define is the desired date of the email delivery as `sendAt` parameter of the `SendEmail` method.
67+
68+
```csharp
69+
try
70+
{
71+
DateTimeOffset sendAtDate = new DateTimeOffset(DateTime.UtcNow.AddMinutes(30), TimeSpan.FromHours(0));
72+
using FileStream attachmentFile = new FileStream(attachmentFilePath, FileMode.Open, FileAccess.Read);
73+
74+
EmailSendResponse sendResponse = sendEmailApi.SendEmail(
75+
"<set your user name>@selfserviceib.com",
76+
"<set your test mail>@<verified email>.com",
77+
"Mail subject text",
78+
text:"Test message with file",
79+
sendAt: sendAtDate);
80+
81+
attachmentFile.Dispose();
4582
}
4683
catch (Exception ex)
4784
{
@@ -52,9 +89,8 @@ Also make sure that from parameter is set to YourUserName@selfserviceib.com.
5289
#### Delivery reports
5390
For each message that you send out, we can send you a delivery report in real-time.
5491
All you need to do is specify your endpoint when sending email in `notifyUrl` field.
55-
You can use data models from the library and the pre-configured `com.infobip.JSON` serializer.
56-
5792
Additionally you can use `messageId` or `bulkId` to fetch reports.
93+
5894
```csharp
5995
try
6096
{
@@ -68,9 +104,3 @@ Additionally you can use `messageId` or `bulkId` to fetch reports.
68104
// HANDLE EXCEPTION
69105
}
70106
```
71-
72-
Exampe of messageId:
73-
74-
```csharp
75-
messageId = "u3qre3bqdxgom8qhq4ae"
76-
```

0 commit comments

Comments
 (0)