Re: [PATCH v2] send-email: add --get-smtp-server option to fetch SMTP settings

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On 4 August 2025 5:21:52 pm IST, Julian Swagemakers <julian@xxxxxxxxxxxxxxx> wrote:
>On Sun Aug 3, 2025 at 3:59 PM CEST, Aditya Garg wrote:
>> On 03/08/25 7:06 pm, Julian Swagemakers wrote:
>>> On Wed Jul 30, 2025 at 5:12 PM CEST, Aditya Garg wrote:
>>>> 
>>>> 2. If that fails, it attempts to fetch the autoconfig file from the email
>>>>   provider's autoconfig URL, which is typically in the format
>>>>   `https://autoconfig.[domain]/mail/config-v1.1.xml?emailaddress=[email]`.
>>> 
>>> The documentation mentions using `DOMAIN/.well-known/autoconfig/mail/`
>>> as an alternative to the autoconfig subdomain, what do you think about
>>> supporting that?
>>
>> Can be supported, but I unfortunately didn't find any email provider having
>> that sort of server to test. Do you have any in mind? Nevertheless, and untested
>> implementation can be done.
>>
>
>I also don't know any hosts supporting this.
>
>>>> +sub parse_config {
>>>> +	require XML::LibXML;
>>>> +	my ($xml, $email) = @_;
>>>> +	my $parser = XML::LibXML->new;
>>>> +	my $doc = eval { $parser->load_xml(string => $xml) };
>>>> +	die "Failed to parse XML\n" unless $doc;
>>>> +	my $config_num = 0;
>>>> +	my $smtp_encryption_config;
>>>> +	my $smtp_user_config;
>>>> +
>>>> +	foreach my $outgoing ($doc->findnodes('//outgoingServer')) {
>>>> +		$config_num++;
>>>> +		if ($outgoing->findvalue('./socketType') eq 'SSL') {
>>>> +			$smtp_encryption_config = 'ssl';
>>>> +		} elsif ($outgoing->findvalue('./socketType') eq 'STARTTLS') {
>>>> +			$smtp_encryption_config = 'tls';
>>>> +		} else {
>>>> +			$smtp_encryption_config = 'plain';
>>> 
>>> 'plain' is unencrypted, I think this should be accompanied by a big
>>> warning.
>>
>> Any ideas on how you want that to be displayed?
>
>How about something like this:
>
>    Found SMTP server settings for example@xxxxxxxxxx:
>
>    Configuration 1:
>      Server: smtp.mail.tiscali.cz
>      Port: 25
>      Encryption: plain
>      Username: example@xxxxxxxxxx
>
>    Warning: Encryption plain is unencrypted!

Looks good!

>
>>>> +		}
>>>> +
>>>> +		if ($outgoing->findvalue('./username') eq '%EMAILADDRESS%') {
>>>> +			$smtp_user_config = $email;
>>>> +		} elsif ($outgoing->findvalue('./username') eq '%EMAILLOCALPART%') {
>>>> +			$smtp_user_config = (split /@/, $email)[0];
>>>> +		} elsif ($outgoing->findvalue('./username') eq '%EMAILDOMAIN%') {
>>>> +			$smtp_user_config = (split /@/, $email)[1];
>>>> +		} else {
>>>> +			$smtp_user_config = $outgoing->findvalue('./username');
>>>> +		}
>>>> +
>>>> +		print "\nConfiguration $config_num:\n";
>>>> +		print "  Server: ", $outgoing->findvalue('./hostname'), "\n";
>>>> +		print "  Port: ", $outgoing->findvalue('./port'), "\n";
>>>> +		print "  Encryption: ", $smtp_encryption_config, "\n";
>>>> +		print "  Username: ", $smtp_user_config, "\n";
>>> 
>>> The new option only gives you the needed SMTP configuration, as a
>>> user you still need to apply them and to do that you will need to
>>> look up how. We could help the user here and give them copy and
>>> paste commands similar to when trying to commit without having an
>>> identity set.
>>
>> Git allows you to set it as global config or repo specific config.
>> I'm not sure how to give a copy/paste command for different needs.
>
>How about something like this:
>
>    Found SMTP server settings for example@xxxxxxxxx:
>
>    Configuration 1:
>      Server: smtp.pobox.com
>      Port: 465
>      Encryption: ssl
>      Username: example@xxxxxxxxx
>
>    Configuration 2:
>      Server: smtp.pobox.com
>      Port: 587
>      Encryption: tls
>      Username: example@xxxxxxxxx
>
>    To apply the settings use:
>
>      git config --global sendmail.smtpServer VALUE
>      git config --global sendmail.smtpServerPort VALUE
>      git config --global sendmail.smtpEncryption VALUE
>      git config --global sendmail.smtpUser VALUE
>
>    Omit --global to set the configuration only in this repository.
>

I will implement this.

>>> The XML file also contains authentication details, what do you think
>>> about processing those? That would also allow adding references to the
>>> documentation in case it is OAuth2.
>>
>> Honestly, app passwords remain as a preferred way to use git send-email.
>> Outlook I guess is just an exception due to obvious reasons. Plus, OAuth2
>> does not tell if the Auth is XOAUTH2 or OAUTHBEARER. Not sure if its worth
>> adding here. I am open to ideas on use cases though, and may try to
>> implement.
>>
>
>I was thinking of something as simple as rendering a message if oauth2
>is one of the options. Something like:
>
>    Found SMTP server settings for example@xxxxxxxxx:
>
>    Configuration 1:
>      Server: smtp.gmail.com
>      Port: 465
>      Encryption: ssl
>      Username: example@xxxxxxxxx
>
>    The SMTP server supports OAuth2 authentication. If you want to use OAuth2,
>    please review the git-send-email man pages for more details.
>

I think this will become crowdy if there are more than 1 configurations.

>>>> +	}
>>>> +}
>>>> +
>>>> +if ($get_smtp_server) {
>>>> +	require URI::Escape;
>>>> +	print "Enter your email address: ";
>>>> +	chomp(my $email = <STDIN>);
>>> 
>>> Someone sending out emails will most likely already have set up
>>> `user.email` in their gitconfig. We could just use that instead of
>>> prompting for user input, or at least suggest it as a default.
>>
>> Suggesting as a default is better then not prompting. Although I think
>> it won't be easy to read the config since all this exits before the config
>> is parsed (I guess?).>
>>> If you don't have an SMTP server configured then `git send-email`
>>> will default to `localhost` and fail if you are not running a
>>> local SMTP server with: `Unable to initialize SMTP properly.
>>> Check config and use --smtp-debug.`. I would suggest altering the
>>> message pointing the user to the new option.
>>
>> "Unable to initialize SMTP properly. Check config and use
>> --smtp-debug. Use --get-smtp-server to get the correct settings for
>> you SMTP server if needed."
>>
>> What do you think about that?
>
>Looks good.
>
>Regards Julian





[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux