6个版本

0.4.0 2023年9月15日
0.3.2 2023年8月17日
0.2.1 2023年8月14日
0.2.0 2023年4月19日

#225 in 电子邮件

Download history 19/week @ 2024-04-01 3/week @ 2024-04-08 5/week @ 2024-04-22 2/week @ 2024-05-06 6/week @ 2024-05-20 6/week @ 2024-06-03 8/week @ 2024-06-10 3/week @ 2024-06-24 41/week @ 2024-07-08 13/week @ 2024-07-15

每月57次下载
dust-mail中使用

MIT许可证

34KB
686

Autoconfig

Crates.io (latest) GitHub Workflow Status

Rust中Mozilla Thunderbird的autoconfig的简单实现。

如果用户需要填写邮件服务器配置,但技术不够熟练,或者只是为了方便而无需手动填写任何内容,这将是很有用的。

在Dust-Mail中用于从用户的电子邮件地址自动发现邮件服务器。

用法

您可以通过调用from_addr函数来请求配置

extern crate autoconfig;

#[tokio::main]
async fn main() {
    let config = autoconfig::from_addr("[email protected]").await.unwrap();

    println!("{}", config.email_provider().id())

    // Outputs:
    // "googlemail.com"
}

您也可以通过域名来实现相同的功能

extern crate autoconfig;

#[tokio::main]
async fn main() {
    let config = autoconfig::from_domain("gmail.com").await.unwrap();

    println!("{}", config.email_provider().id())

    // Outputs:
    // "googlemail.com"
}

示例

以下是一个配置结构体可能的样子示例

Config {
        version: "1.1",
        email_provider: EmailProvider {
            id: "googlemail.com",
            properties: [
                Domain("gmail.com"),
                Domain("googlemail.com"),
                Domain("google.com"),
                DisplayName("Google Mail"),
                DisplayShortName("GMail"),
                IncomingServer(Server {
                    r#type: Imap,
                    properties: [
                        Hostname("imap.gmail.com"),
                        Port(993),
                        SocketType(Tls),
                        Username("%EMAILADDRESS%"),
                        Authentication(OAuth2),
                        Authentication(PasswordCleartext),
                    ],
                }),
                IncomingServer(Server {
                    r#type: Pop3,
                    properties: [
                        Hostname("pop.gmail.com"),
                        Port(995),
                        SocketType(Tls),
                        Username("%EMAILADDRESS%"),
                        Authentication(OAuth2),
                        Authentication(PasswordCleartext),
                        Pop3(Pop3Config {
                            leave_messages_on_server: true,
                            download_on_biff: None,
                            days_to_leave_messages_on_server: None,
                            check_interval: None,
                        }),
                    ],
                }),
                OutgoingServer(Server {
                    r#type: Smtp,
                    properties: [
                        Hostname("smtp.gmail.com"),
                        Port(465),
                        SocketType(Tls),
                        Username("%EMAILADDRESS%"),
                        Authentication(OAuth2),
                        Authentication(PasswordCleartext),
                    ],
                }),
                Documentation(Documentation {
                    url: "http://mail.google.com/support/bin/answer.py?answer=13273",
                    properties: [
                        DocumentationDescription {
                            lang: None,
                            description: "How to enable IMAP/POP3 in GMail",
                        },
                    ],
                }),
                Documentation(Documentation {
                    url: "http://mail.google.com/support/bin/topic.py?topic=12806",
                    properties: [
                        DocumentationDescription {
                            lang: None,
                            description: "How to configure email clients for IMAP",
                        },
                    ],
                }),
                Documentation(Documentation {
                    url: "http://mail.google.com/support/bin/topic.py?topic=12805",
                    properties: [
                        DocumentationDescription {
                            lang: None,
                            description: "How to configure email clients for POP3",
                        },
                    ],
                }),
                Documentation(Documentation {
                    url: "http://mail.google.com/support/bin/answer.py?answer=86399",
                    properties: [
                        DocumentationDescription {
                            lang: None,
                            description: "How to configure TB 2.0 for POP3",
                        },
                    ],
                }),
            ],
        },
        oauth2: Some(OAuth2Config {
            issuer: "accounts.google.com",
            scope: "https://mail.google.com/ https://www.googleapis.com/auth/contacts https://www.googleapis.com/auth/calendar https://www.googleapis.com/auth/carddav",
            auth_url: "https://127.0.0.1/o/oauth2/auth",
            token_url: "https://www.googleapis.com/oauth2/v3/token",
        }),
    };

依赖项

~21–38MB
~689K SLoC