Comments (3)
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.
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.
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)
- ✨ Feature request: OpenPGP encryption support HOT 18
- thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: MissingStartTls HOT 7
- Add an `impl std::error::Error` for `mail_send::Error` HOT 4
- `UnparseableReply`: Bug in `impl<T: AsyncRead + AsyncWrite + Unpin> SmtpClient<T>`. (Fixed by #13) HOT 5
- Sample Usage using XOAuth2 for SMTP Sending of Email HOT 2
- Disable SSL/TLS HOT 1
- Non-async support? HOT 4
- some error with error display (i don't know how to describe accurate) HOT 2
- Fails to compile (Even in hello world) HOT 1
- Send gets stuck when the message has a binary attachment HOT 10
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mail-send.