Giter VIP home page Giter VIP logo

Comments (3)

mdecimus avatar mdecimus commented on May 23, 2024

Hi,

Do you need to send the email exactly as it was? If that is the case, you could send it in raw format as in this example:

https://github.com/stalwartlabs/mail-send/blob/main/examples/smtp_raw_message.rs

from mail-send.

mripard avatar mripard commented on May 23, 2024

It works indeed, but we would still need to parse the raw message using MessageParser in order to retrieve the to and from fields.

We end up with something like this

use mail_builder::MessageBuilder;
use mail_parser::Message as MessageParser;
use mail_send::{smtp::message::Message, Transport};

#[tokio::main]
async fn main() {
    let message = MessageBuilder::new()
        .from(("Test", "[email protected]"))
        .to("[email protected]")
        .subject("Test Email")
        .text_body("Hi Mark!");

    let bytes = message.write_to_vec()
        .unwrap();

    let msg = MessageParser::parse(&bytes)
        .unwrap();

    let from = match msg.get_from() {
        mail_parser::HeaderValue::Address(address) => address.address.as_ref().unwrap(),
        _ => todo!(),
    }.to_string();

    let to = match msg.get_to() {
        mail_parser::HeaderValue::Address(address) => address.address.as_ref().unwrap(),
        _ => todo!(),
    }.to_string();

    let msg_sent = Message::empty()
        .from(from)
        .to(to)
        .body(&bytes);

    Transport::new("smtp.example.org")
        .credentials("[email protected]", "passwd")
        .connect_tls()
        .await
        .unwrap()
        .send(msg_sent)
        .await
        .unwrap()
}

Which is still fairly tedious (and possibly incomplete)

from mail-send.

mripard avatar mripard commented on May 23, 2024

did you add something to 0.2.2 to make this any easier? I didn't find anything obvious to me

from mail-send.

Related Issues (11)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.