December 27, 2023

Sending emails through GMail on Windows

 


Sending emails through GMail using the Windows Command Line Interface (CLI) can be accomplished through two distinct methods: one utilizing PowerShell (PS1) and the other through the Command Prompt (cmd). Before proceeding, ensure you have obtained an application password for your GMail account.


PowerShell Method:

No additional software is required for this approach. Utilize the following example:

$EmailFrom = "[email protected]"
$EmailTo = "[email protected]"
$Subject = "PS1 email test"
$Body = "Hello there"
$SMTPServer = "smtp.gmail.com"
$SMTPClient = New-Object Net.Mail.SmtpClient($SMTPServer, 587)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential("[email protected]", "AppPassword")
$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)


CMD:

For this, you need to download the mailsend software from https://github.com/muquit/mailsend/releases.

mailsend -to RECIPIENT@hello.com -from [email protected]^
  -starttls -port 587 -auth^
  -smtp smtp.gmail.com^
  -sub "test" +cc +bc -v^
  -user "[email protected]" -pass "AppPassword"^
  -M "Hello there"


Note: Ensure you replace placeholders like "[email protected]," "[email protected]" and others with your actual email addresses. Additionally, use the correct application password obtained for your GMail account.


Send emails from Ubuntu with GMail account





If you're looking to send emails from your Ubuntu system using a GMail account, here's a straightforward method using Postfix. Follow these steps to set it up:


Prerequisites:

Ensure you have an application password for your GMail account.


On Ubuntu:

1. Install the necessary software:

$ sudo apt-get update
$ sudo apt-get install postfix mailutils libsasl2-2 ca-certificates libsasl2-modules


2. Edit or add the following lines in the file /etc/postfix/main.cf:

relayhost = [smtp.gmail.com]:587
smtp_tls_security_level=encrypt
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_use_tls = yes


3. Add your GMail account and app password to /etc/postfix/sasl_passwd:

[smtp.gmail.com]:587  [email protected]:YOUR_APP_PASSWORD


4. Set permissions:

$ sudo chmod 400 /etc/postfix/sasl_passwd


5. Generate the password file to create /etc/postfix/sasl_passwd.db:

$ sudo postmap /etc/postfix/sasl_passwd


6. Check and restart Postfix:

$ sudo postfix check
$ sudo systemctl restart postfix
$ sudo systemctl status postfix


7. Test the setup:

$ echo "Hello World" | mail -s "Email from Ubuntu using GMail" [email protected]
$ tail /var/log/mail.log


That's it! You should now be able to send emails from your Ubuntu system using your GMail account through Postfix.



December 25, 2023

Use GMail with Gitea



To integrate GMail with your Gitea system, follow these steps:

  1. Generate Google Application Password:
    Obtain a Google Application Password for secure authentication. You can generate one in your Google Account settings, especially if two-factor authentication is enabled.

  2. Edit Gitea Configuration:
    Use a text editor to modify the Gitea configuration file (/etc/gitea/app.ini). Add the following settings under the [mailer] section:

    [mailer]
    ENABLED = true
    SMTP_ADDR = smtp.gmail.com
    SMTP_PORT = 465
    FROM = <google gmail account email address>
    USER = <google gmail account email address>
    PASSWD = <google app password here>
    PROTOCOL = smtps


    Adjust the values according to your Gmail account and the generated application password.

  3. Restart Gitea:
    Restart the Gitea service to apply the new configuration:

    $ systemctl restart gitea

  4. Test Email Configuration:
    Access the Admin Settings screen in Gitea, and initiate a test email. This step ensures that the Gmail integration is functioning correctly.
By following these steps, you'll enable Gitea to use your Gmail account for sending email notifications and other communication. Ensure that the provided Gmail application password is secure and follows best practices for authentication.