Lua
Lua
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 Lua Downloads
local chilkat = require("chilkat")
-- This example requires the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
local mailman = chilkat.MailMan.new()
mailman.smtp_host = "smtp.office365.com"
mailman.smtp_port = 587
mailman.start_tls = true
-- This could be your hotmail.com, live.com, or outlook.com account.
mailman.smtp_username = "yourName@live.com"
-- Load the previously saved OAuth2 access token.
local json = chilkat.JsonObject.new()
local success = json:load_file("qa_data/tokens/hotmail.json")
if not success then
print(json.last_error_text)
return
end
mailman.oauth2_access_token = json:string_of("access_token")
local email = chilkat.Email.new()
-- Note: If you send an email such as this, it can easily go to your Junk or Trash email folders.
email.subject = "This is a test"
email.body = "This is a test"
-- This could be your hotmail.com, live.com, or outlook.com account.
email.from = "My Hotmail Account <yourName@live.com>"
success = email:add_to("Joe Example", "joe@example.com")
success = mailman:open_smtp_connection()
if not success then
print(mailman.last_error_text)
print("ConnectFailReason = " .. mailman.connect_fail_reason)
return
end
success = mailman:smtp_authenticate()
if not success then
print(mailman.last_error_text)
return
end
success = mailman:send_email(email)
if not success then
print(mailman.last_error_text)
return
end
mailman:close_smtp_connection()
print("Email Sent.")