admin管理员组文章数量:1401444
I am using microsoft graph api to send mails to both outlook/outlook based emails and gmails for email verification from my outlook email. The user is receiving the mails but in case of gmail based emails, the otp message which i wanna show is going as protected message/encrypted one. I tried adding headers to the mail content, still wasnt useful. Also i am using Rust to do this. And here is my send_email fn in rust.
// sending email
pub async fn send_email(pool: &PgPool, recipient: &str, otp: &str) -> Result<(), Box<dyn std::error::Error>> {
let access_token = get_access_token(pool).await?;
let config = get_configuration().expect("Failed to read configuration");
let sender_email = &config.oauth.sender_email;
// Create HTML formatted email body
let html_content = format!(
r#"
<div style="font-family: Arial, sans-serif; padding: 20px; max-width: 600px;">
<p>Dear Customer,</p>
<p>Thank you for showing interest in our SaaS Application.</p>
<p>To verify your email, please enter the following One Time Password (OTP):</p>
<p style="font-size: 18px; font-weight: bold;">{}</p>
<p>The OTP is valid for <strong>3</strong> minutes from the receipt of this email.</p>
<p>If you did not request this OTP, please ignore this email.</p>
<p>Thank you</p>
</div>
"#,
otp
);
let client = Client::new();
let email_body = json!({
"message": {
"subject": "Your OTP Code",
"body": {
"contentType": "HTML",
"content": html_content
},
"toRecipients": [{
"emailAddress": { "address": recipient }
}],
"from": {
"emailAddress": { "address": sender_email }
},
"importance": "normal",
"internetMessageHeaders": [
{
"name": "X-Microsoft-Exchange-Organization-SkipSafeLinksProcessing",
"value": "1"
},
{
"name": "X-Microsoft-Exchange-Organization-SkipSafeAttachmentsProcessing",
"value": "1"
},
{
"name": "X-MS-Exchange-Organization-Classification",
"value": "Normal"
},
{
"name": "X-MS-Exchange-Organization-Message-Timestamp",
"value": chrono::Utc::now().to_rfc3339()
},
{
"name": "X-Proofpoint-Encrypt",
"value": "off"
}
]
},
"saveToSentItems": "false"
});
let response = client
.post(".0/me/sendMail")
.header("Authorization", format!("Bearer {}", access_token))
.header("Content-Type", "application/json")
.json(&email_body)
.send()
.await?;
if response.status().is_success() {
Ok(())
} else {
let error_text = response.text().await?;
Err(format!("Failed to send email: {}", error_text).into())
}
}
本文标签:
版权声明:本文标题:Turn off encryption while sending mails to gmail from the outlook using microsoft graph api in Rust - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744260565a2597695.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论