Get started with the Digipost API
It is really easy to integrate with Digipost and send your first digital mail. Vi suggest you use one of our client libraries to get started. Follow these three simple steps:
1. Get registered as a Digipost sender
All organisations that wish to send digital mail must have a Digipost organisation (sender) account. To get a test account, send an email to support@digipost.no with the following information:
- Organisastion name
- Organisation number
- Telephone number
- Email address
- The Digipost addresses of the people who should have access
2. Choose between the Java or .NET Digipost client libraries
Use the Digipost client library in either Java or .NET to send requests to the Digipost API. You can also integrate directly with the API, but we recommend using a client library.
Java client library .NET client library
3. Call Digipost client library code from your code
All it takes is a few lines of code to send digital mail. The following code shows a bare bones example of how to do this. There are many other options and possibilities in the client libraries and Digipost API, but the below is quick introduction to how sending a letter to a Digipost recipient works.
Java
// 1. Les inn sertifikatet du har knyttet til din Digipost-konto (i .p12-formatet)
Signer signer;
try (InputStream sertifikatInputStream = Files.newInputStream(Paths.get("certificate.p12"))) {
signer = Signer.usingKeyFromPKCS12KeyStore(sertifikatInputStream, "TheSecretPassword");
}
// 2. Opprett en DigipostClient
SenderId senderId = SenderId.of(123456); // Din konto-ID
DigipostClient client = new DigipostClient(
DigipostClientConfig.newConfiguration().build(), senderId.asBrokerId(), signer
);
// 3. Opprett et fødselsnummerobjekt
PersonalIdentificationNumber pin = new PersonalIdentificationNumber("26079833787");
// 4. Opprett hoveddokumentet
UUID documentUuid = UUID.randomUUID();
Document primaryDocument = new Document(documentUuid, "Dokumentets emne", PDF);
// 5. Opprett en forsendelse
Message message = newMessage("din-forsendelses-id", primaryDocument)
.personalIdentificationNumber(pin)
.build();
// 6. Legg til innhold og send
client.createMessage(message)
.addContent(primaryDocument, Files.newInputStream(Paths.get("content.pdf")))
.send();
.NET
// 1. Initialiser konfig med din Digipost avsender id
// Avsender id finner du på digipost.no/bedrift
var config = new ClientConfig(senderId: "xxxxx", environment: Environment.Production);
// 2. Initialiser klient med thumbprint til sertifikat som er knyttet til din Digipost virksomhetskonto
// Virksomhetssertifikat knyttes til din Digipost konto på digipost.no/bedrift.
// Informasjon om bruk av thumbprints finnes på http://digipost.github.io/digipost-api-client-dotnet/#installcert.
var client = new DigipostClient(config, thumbprint: "84e492a972b7e...");
// 3. Lag melding med bruk av fødselsnummer som personidentifikator
var message = new Message(
new RecipientById(IdentificationType.PersonalIdentificationNumber, "00000000000"),
new Document(subject: "Dokumentets emne", fileType: "pdf", path: @"c:\...\dokument.pdf")
);
// 4. Send melding
var result = client.SendMessage(message);
Next steps
Now that you have completed a test integration, the next step is to implement the full integration in your application or system. Read our guide to integration (in Norwegian) to see which steps are typically involved in implementing a production-ready integration with Digipost.
For additional questions you may have, see our FAQ. You can also contact Digipost regarding integration questions.
If your organisation is considered public sector and you are looking for information about Digdir’s digital mail program, see Digdir’s web pages on this topic.