Rust
Rust
Send Email with Multiple Reply-To Addresses
See more SMTP Examples
Send email with multiple repy-to addresses.Note: Some mail servers will remove the extra email addresses from the Reply-To header. Even if you provide multiple reply-to addresses, the email may arrive with only the 1st.
Chilkat Rust Downloads
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let mailman = chilkat::MailMan::new();
mailman.set_smtp_host("smtp.my_mail_server.com");
mailman.set_smtp_username("myUsername");
mailman.set_smtp_password("myPassword");
mailman.set_smtp_port(465);
mailman.set_smtp_ssl(true);
// Create a new email object
let email = chilkat::Email::new();
email.set_subject("This is a test");
email.set_body("This is a test");
email.set_from("Joe <joe@example.com>");
let _ = email.add_to("Mary", "mary@example2.com").is_ok();
// Specify a single reply-to address, which will get replace with a list of addresses..
email.set_reply_to("placeholder@example.com");
// Get the email as MIME.
let sb_mime = chilkat::StringBuilder::new();
let _ = mailman.render_to_mime_sb(&email, &sb_mime);
// Update the Reply-To MIME header with a list of email addresses.
let reply_to_addrs = "joe@example.com, mike@example.com".to_string();
let _ = sb_mime.replace_all_between("Reply-To: ", "\r\n", &reply_to_addrs, false);
// Examine the MIME to be sent:
println!("{}", sb_mime.get_as_string().unwrap_or_default());
// Here's the MIME:
// MIME-Version: 1.0
// Date: Tue, 03 Sep 2024 08:18:12 -0500
// Message-ID: <D892B0E563A7A13B1F499530DE21529714EA479A@SLICE>
// Content-Type: text/plain; charset=us-ascii; format=flowed
// Content-Transfer-Encoding: 7bit
// X-Priority: 3 (Normal)
// Subject: This is a test
// From: Joe <joe@example.com>
// To: Mary <mary@example2.com>
// Reply-To: joe@example.com, mike@example.com
//
// This is a test
// ---------
// Send the MIME...
if mailman.send_mime("joe@example.com", "mary@example2.com", &sb_mime.get_as_string().unwrap_or_default()).is_err() {
println!("{}", mailman.last_error_text());
return;
}
if mailman.close_smtp_connection().is_err() {
println!("Connection to SMTP server not closed cleanly.");
}
println!("Mail Sent!");