Zig
Zig
Send Email with hotmail.com, live.com, or outlook.com
See more SMTP Examples
Send email using your Microsoft hotmail.com, live.com, or outlook.com account via the smtp.office365.com SMTP server.See the Guide for Creating an Application to Send Email from Hotmail.com, Live.com, or Outlook.com
Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const mailman = try chilkat.MailMan.init();
defer mailman.deinit();
mailman.setSmtpHost("smtp.office365.com");
mailman.setSmtpPort(587);
mailman.setStartTLS(true);
// This could be your hotmail.com, live.com, or outlook.com account.
mailman.setSmtpUsername("yourName@live.com");
// Load the previously saved OAuth2 access token.
const json = try chilkat.JsonObject.init();
defer json.deinit();
json.loadFile("qa_data/tokens/hotmail.json") catch {
std.debug.print("{s}\n", .{try json.getLastErrorText(alloc)});
return;
};
mailman.setOAuth2AccessToken(try json.stringOf(alloc, "access_token"));
const email = try chilkat.Email.init();
defer email.deinit();
// Note: If you send an email such as this, it can easily go to your Junk or Trash email folders.
email.setSubject("This is a test");
email.setBody("This is a test");
// This could be your hotmail.com, live.com, or outlook.com account.
email.setFrom("My Hotmail Account <yourName@live.com>");
try email.addTo("Joe Example", "joe@example.com");
mailman.openSmtpConnection() catch {
std.debug.print("{s}\n", .{try mailman.getLastErrorText(alloc)});
std.debug.print("ConnectFailReason = {d}\n", .{mailman.getConnectFailReason()});
return;
};
mailman.smtpAuthenticate() catch {
std.debug.print("{s}\n", .{try mailman.getLastErrorText(alloc)});
return;
};
mailman.sendEmail(email) catch {
std.debug.print("{s}\n", .{try mailman.getLastErrorText(alloc)});
return;
};
mailman.closeSmtpConnection() catch {};
std.debug.print("Email Sent.\n", .{});
}