[−][src]Struct mailgun_api::api::MailgunApi
MailgunApi struct where include all the endpoints
Implementations
impl MailgunApi
[src]
pub fn new(api_key: &str, endpoint: &str, domain: &str) -> Self
[src]
Set the mailgun paramenters
pub async fn send_email<T, '_>(
&'_ mut self,
email_params: EmailParams
) -> Result<T, Error> where
T: DeserializeOwned,
[src]
&'_ mut self,
email_params: EmailParams
) -> Result<T, Error> where
T: DeserializeOwned,
Send an email
Example:
#[tokio::test] async fn shoul_send_email_with_text() { use super::EmailParams; use dotenv::dotenv; use std::env; dotenv().ok(); let mailgun_secret = env::var("MAILGUN_SECRET").expect("MAILGUN_SECRET must be set"); let mailgun_domain = env::var("MAILGUN_DOMAIN").expect("MAILGUN_DOMAIN must be set"); let mailgun_endpoint = env::var("MAILGUN_ENDPOINT").expect("MAILGUN_ENDPOINT must be set"); let sender = env::var("EMAIL_FROM").expect("MAIL_FROM must be set"); let receiver = env::var("EMAIL_RECEIVER_TEST").expect("EMAIL_RECEIVER_TEST must be set"); let params = EmailParams { from: sender, to: receiver, subject: "test mailgung api".to_string(), text: Some("hello this is a test".to_string()), html: None, }; let mut mailgun = MailgunApi::new(&mailgun_secret, &mailgun_endpoint, &mailgun_domain); let response = mailgun.send_email::<HashMap<String, String>>(params).await; assert_eq!(response.is_ok(), true) }
pub async fn get_all_events<T, '_>(&'_ mut self) -> Result<T, Error> where
T: DeserializeOwned,
[src]
T: DeserializeOwned,
Get all the events
Example:
#[tokio::test] async fn should_get_all_the_events() { use super::Events; use dotenv::dotenv; use std::env; dotenv().ok(); let mailgun_secret = env::var("MAILGUN_SECRET").expect("MAILGUN_SECRET must be set"); let mailgun_domain = env::var("MAILGUN_DOMAIN").expect("MAILGUN_DOMAIN must be set"); let mailgun_endpoint = env::var("MAILGUN_ENDPOINT").expect("MAILGUN_ENDPOINT must be set"); let mut mailgun = MailgunApi::new(&mailgun_secret, &mailgun_endpoint, &mailgun_domain); let response = mailgun.get_all_events::<Events>().await.unwrap(); println!("Response: {:#?}", response); }
pub async fn get_message_by_id<T, '_, '_>(
&'_ mut self,
message_id: &'_ str
) -> Result<T, Error> where
T: DeserializeOwned,
[src]
&'_ mut self,
message_id: &'_ str
) -> Result<T, Error> where
T: DeserializeOwned,
Get a message content by Id
Example
#[tokio::test] async fn should_get_message_by_id() { use super::{Events, ReceiveMessage}; use dotenv::dotenv; use std::env; dotenv().ok(); let mailgun_secret = env::var("MAILGUN_SECRET").expect("MAILGUN_SECRET must be set"); let mailgun_domain = env::var("MAILGUN_DOMAIN").expect("MAILGUN_DOMAIN must be set"); let mailgun_endpoint = env::var("MAILGUN_ENDPOINT").expect("MAILGUN_ENDPOINT must be set"); let mut mailgun = MailgunApi::new(&mailgun_secret, &mailgun_endpoint, &mailgun_domain); let events = mailgun.get_all_events::<Events>().await.unwrap(); let response = mailgun .get_message_by_id::<ReceiveMessage>(&events.items[events.items.len() - 1].storage.key) .await .unwrap(); println!("Response: {:#?}", response); }
Auto Trait Implementations
impl RefUnwindSafe for MailgunApi
impl Send for MailgunApi
impl Sync for MailgunApi
impl Unpin for MailgunApi
impl UnwindSafe for MailgunApi
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,