# # Wesleyan University # COMP 332, Spring 2023 # # Sending email using openssl # #========================================================= # Connect to mail server. E.g., #========================================================= # Wesleyan mail server: openssl s_client -connect smtp.office365.com:587 -crlf -starttls smtp or openssl s_client -connect smtp.office365.com:587 -starttls smtp See https://support.microsoft.com/en-us/office/pop-imap-and-smtp-settings-8361e398-8af4-4e97-b147-6c6c4ac95353 # Gmail mail server openssl s_client -crlf -connect smtp.gmail.com:465 See https://support.google.com/accounts/answer/6010255?hl=en&visit_id=638000770276463957-4140133283&p=less-secure-apps&rd=1 # From the server you should see something like 220 exchcas3.wesad.wesleyan.edu Microsoft ESMTP MAIL Service ready at Wed, 21 Sep 2016 12:19:27 -0400 OR 220 smtp.gmail.com ESMTP o7-20020a05622a008700b003b62e8b77e7sm351052qtw.68 - gsmtp 250 SMTPUTF8 #========================================================= # Say hello #========================================================= # Type at hanging prompt a HELO or Extended HELO (EHLO) # including your sending domain (although not clear it matters # what you type here), and I've just been typing my email username EHLO vumanfredi # From the server you should see something like the following in response 250-BL0PR01CA0007.outlook.office365.com Hello [24.34.220.212] OR 250-smtp.gmail.com at your service, [24.34.220.212] #========================================================= # Authentication time #========================================================= # First convert your username and password to binary. Type # these commands in a separate terminal, using your username # and replacing password with your password. You'll get # back some base64 encoded strings that you will enter at the # hanging SMTP prompt. If you're using gmail (and 2-factor # authentication you may need to generate an app password, # see the following website for more details https://support.google.com/accounts/answer/185833?p=InvalidSecondFactor&visit_id=1-636100677231869734-2558592835&rd=1 perl -MMIME::Base64 -e 'print encode_base64("username\@wesleyan.edu")' perl -MMIME::Base64 -e 'print encode_base64("password")' If your password begins with a Q when base64-encoded, pass -quiet to the openssl s_client to not close the connection with a DONE # Enter those base64 encoded strings at the SMTP prompt # To do so, first type auth login # You should see in response, something like 334 kagkNDcg32bc # Paste your username string and press enter. You should see in response # something like, 334 rpMeg1m4jnnz # Now paste your password string. You should see in response: 250 2.1.5 Recipient OK Or 535 5.7.139 Authentication unsuccessful, SmtpClientAuthentication is disabled for the Tenant. Visit https://aka.ms/smtp_auth_disabled for more information. Or 534-5.7.9 Application-specific password required. Learn more at 534 5.7.9 https://support.google.com/mail/?p=InvalidSecondFacto (if you have 2-step-verification) #========================================================= # Generate the email #========================================================= # Specify the sender by typing the following at prompt. # Note the use of brackets: < > MAIL FROM: # You should see in response 250 2.1.0 Sender OK # Specify the receiver by typing the following at prompt. # Note that "rcpt to:" is in lower case. The "r" is really # all that needs to be lower case. Upper case R tells openssl # you want to renegotiate, which you do not want to do. So # this is just a hack for dealing with openssl rcpt to: # You should see in response 250 2.1.5 Recipient OK # Now generate and send the data. Type at the prompt DATA # You should see in response 354 Start mail input; end with . OR 354 Go ahead qkg.23 - gsmtp # Enter the data to send. E.g., From: me To: you Subject: test . # You may want to try not including the To: you line if things don't work # You should see in response, something like 250 2.6.0 [InternalId=37375198] Queued mail for delivery OR 250 2.0.0 OK qkg.23 - gsmtp #========================================================= # Done. Close connection #========================================================= QUIT