Closed xamantra closed 3 years ago
Please note that you do not need to use the autodiscovery feature when using the high level API.
Instead you can also specify the relevant servers directly, but this involves quite some code, so I have now added the MailAccount.fromManualSettings() methods in commit bf54846767e2c26eaef313339f49b308469bea35:
/// Creates a mail account from manual settings with a simple user-name/password authentication.
///
/// You need to specify the account [name], the associated [email], the [incomingHost], [outgoingHost] and [password].
/// When the [userName] is different from the email, it must also be specified.
/// You should specify the [outgoingClientDomain] for sending messages, this defaults to `enough.de`.
/// The [incomingType] defaults to [ServerType.imap], the [incomingPort] to `993` and the [incomingSocketType] to [SocketType.ssl].
/// The [outgoingType] defaults to [ServerType.smtp], the [outgoingPort] to `465` and the [outgoingSocketType] to [SocketType.ssl].
static MailAccount fromManualSettings(
String name,
String email,
String incomingHost,
String outgoingHost,
String password, {
ServerType incomingType = ServerType.imap,
ServerType outgoingType = ServerType.smtp,
String? userName,
String outgoingClientDomain = 'enough.de',
incomingPort = 993,
outgoingPort = 465,
SocketType incomingSocketType = SocketType.ssl,
SocketType outgoingSocketType = SocketType.ssl,
}) {
final auth = PlainAuthentication(userName ?? email, password);
return fromManualSettingsWithAuth(
name, email, incomingHost, outgoingHost, auth,
incomingType: incomingType,
outgoingType: outgoingType,
outgoingClientDomain: outgoingClientDomain);
}
/// Creates a mail account from manual settings with the specified [auth]entication.
///
/// You need to specify the account [name], the associated [email], the [incomingHost], [outgoingHost] and [auth].
/// You can specify a different authentication for the outgoing server using the [outgoingAuth] parameter.
/// You should specify the [outgoingClientDomain] for sending messages, this defaults to `enough.de`.
/// The [incomingType] defaults to [ServerType.imap], the [incomingPort] to `993` and the [incomingSocketType] to [SocketType.ssl].
/// The [outgoingType] defaults to [ServerType.smtp], the [outgoingPort] to `465` and the [outgoingSocketType] to [SocketType.ssl].
static MailAccount fromManualSettingsWithAuth(
String name,
String email,
String incomingHost,
String outgoingHost,
MailAuthentication auth, {
ServerType incomingType = ServerType.imap,
ServerType outgoingType = ServerType.smtp,
MailAuthentication? outgoingAuth,
String outgoingClientDomain = 'enough.de',
incomingPort = 993,
outgoingPort = 465,
SocketType incomingSocketType = SocketType.ssl,
SocketType outgoingSocketType = SocketType.ssl,
}) {
final incoming = MailServerConfig()
..authentication = auth
..serverConfig = ServerConfig(
type: incomingType,
hostname: incomingHost,
port: incomingPort,
socketType: incomingSocketType,
);
final outgoing = MailServerConfig()
..authentication = outgoingAuth ?? auth
..serverConfig = ServerConfig(
type: outgoingType,
hostname: outgoingHost,
port: outgoingPort,
socketType: outgoingSocketType,
);
final account = MailAccount()
..name = name
..email = email
..incoming = incoming
..outgoing = outgoing
..outgoingClientDomain = outgoingClientDomain;
return account;
}
This is not yet released but available in Git. You can use the above code now, too.
The release v1.3.3 contains the API improvement
Okay. I will try this.
Full code
(taken from readme sample, modified a bit)
Logs
enough_mail:
1.3.2