Looking for Postfix virtual_mailbox_maps lookup for usernames only, not email addresses - postfix-mta

I have a postfix accepting mails for 2 domains, example.org, example.com and example.net.
I have a single mailbox for the three domains. Emails to USERNAME#example.org, USERNAME#example.com and USERNAME#example.net go to the same mailbox.
I use postfix to manage the domains, accounts and alias.
I use:
virtual_mailbox_maps = pgsql:/etc/postfix/scripts/sql_virtual_mailboxes.cf
with the query:
user = username
password = password
hosts = localhost
dbname = mail
query = SELECT 1 FROM virtual_users WHERE domain='%s' AND active = '1'
This works fine but it forces me to add 3 entries in the table virtual_users with the 3 possible emails and the same password because I want users to use any of the three domains to send emails and authenticate themselves.
I would like to modify the Table virtual_users using only the USERNAME and find a query that checks if a USERNAME exist, not the complete email as I have today.
How can I modify the virtual_mailbox_maps query to check for the USERNAME only and not the complete email?

replace %s (email) by %n (username) in
user = username
password = password
hosts = localhost
dbname = mail
query = SELECT 1 FROM virtual_users WHERE domain='%n' AND active = '1'

Related

Hide or encrypt ps1 credentials

i'm having an issue with my ps1 script to send mails. The problem, I have to send this script to multiple users and I dont want them to read my smtp credentials from the mail sender, is there any way to encrypt or hide the password line only, and still can be executed?
$Username = "test"
$EmailPassword = "jlkajdksajeqw"
$Attachment= "c:\validacion.zip"
$EmailTo = ("seleccionestmk#gmail.com")
$EmailFrom = "seleccionestmk#telemercado.com.ar"
$Subject = "Validacion BPC"
$Body= "Validacion realizada, dentro del archivo zip, se encuentran los datos necesarios para aprobar o denegar la validacion. Saludos"
$SMTPServer = "mail.telemercado.com.ar"
$SMTPMessage = New-Object System.Net.Mail.MailMessage($EmailFrom, $EmailTo, $Subject, $Body)
$Attachment = New-Object System.Net.Mail.Attachment($Attachment)
$SMTPMessage.Attachments.Add($Attachment)
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
$SmtpClient.UseDefaultCredentials = $false
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential($Username, $EmailPassword)
$SMTPClient.Send($SMTPMessage)
If you encrypt the sensitive values somehow then the receiver of the script needs the decryption key in order to read the sensitive values to run the script.
You could run some kind of obfuscation software over your script to make it harder for the receiver of the script to extract the sensitive values, but you can never prevent such an extraction.
The best way would be to re-engineer the system in such a way that giving the credentials to the users is not an issue. For example, scope the email account from which emails are sent in such a way that it is used only for this one use case and all the users that you give the script to are also supposed to use it as such. If you're using the email account for other things then move them to a different account with different credentials.
Another way would be to create a server endpoint which validates the personalized credentials of the users (you need to give each user their own credentials) that you gave the script to and stores the credentials for the email account only on the server. The server would need to validate the fields that they conform to the way this email account should be used.

CDO.Message To and From Fields Changed to "Friendly Name" and Email Address

When I first created this Classic ASP script, with the help of W3Schools, to send email, it worked fine. Now I'm having issues with sending the actual email; it appears to hang on the .Send method.
I noticed that when I set the To and From email address to just the email address, it reformats it to a "Friendly Name"/Email Address format:
myMail.From="Support#myDomain.com"
Response.Write myMail.From
The output of the Response Write is:
"Support#myDomain.com" <Support#myDomain.com>
I don't know if this was happening before, or if I should be setting the To and From fields in this format. Just to check if this is causing my problem, is there anyway to prevent these fields from being changed from just the email address?
Maybe the e-mail sending from the server now needs some kind of authentication such as setting these fields:
' Outgoing SMTP server.
objCDO.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.mydomain.com"
objCDO.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objCDO.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objCDO.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
' Type of authentication, 0=NONE, 1-Basic (Base64 encoded), and 2=NTLM.
objCDO.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
' UserID on the SMTP server
objCDO.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "support#mydomain.com"
' Password on the SMTP server
objCDO.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "myemailpassword"
' Update config.
objCDO.Configuration.Fields.Update
The issue stemmed from the fact that the "From" email address was actually a distribution list and the account credentials used to login to the email server were not authorized to "Send As". Once that was rectified emails sent without further problems.
Thanks for the response.

Forgot Oracle username and password, how to retrieve?

I have forgotten my Oracle username and password and hence not able to use it. My Oracle version is 11.2.0.1.0(11g). I consulted Internet. They asked me to execute commands like ‘SYSDBA’ but I was unable to do it as once I give ‘SYSDBA’ on Command Prompt screen, it takes the command as the username and next asks for password. I cannot execute any commands suggested by them as whatever I enter is taken as the username, subsequently password is asked and error occurs.
Open your SQL command line and type the following:
SQL> connect / as sysdba
Once connected,you can enter the following query to get details of username and password:
SQL> select username,password from dba_users;
This will list down the usernames,but passwords would not be visible.But you can identify the particular username and then change the password for that user.
For changing the password,use the below query:
SQL> alter user username identified by password;
Here username is the name of user whose password you want to change and password is the new password.
Go to SQL command line:-
type:
sql>connect / as sysdba;
then type:
sql>desc dba_users;
then type:
sql>select username,password from dba_users;
If sysdba doesn't work then try connecting with username:scott and password: Tiger
You will be able to see all users with passwords.
Probably you might find your's.
Hope this helps
Open Command Prompt/Terminal and type:
sqlplus / as SYSDBA
SQL prompt will turn up. Now type:
ALTER USER existing_account_name IDENTIFIED BY new_password ACCOUNT UNLOCK;
Voila! You've unlocked your account.
The usernames are shown in the dba_users's username column, there is a script you can run called:
alter user username identified by password
You can get more information here - https://community.oracle.com/thread/632617?tstart=0
if you are on Windows
Start the Oracle service if it is not started (most probably it starts automatically when Windows starts)
Start CMD.exe
in the cmd (black window) type:
sqlplus / as sysdba
Now you are logged with SYS user and you can do anything you want (query DBA_USERS to find out your username, or change any user password). You can not see the old password, you can only change it.

Access denied for user 'myusername'#'localhost' (using password: YES)

I am on windows using Xampp
I want to upload a file on shiny, but I receive this error; Access denied for user 'myusername'#'localhost' (using password: YES)
This is what I have in R:
mysql = list(
"host" = "127.0.0.1",
"port" = 3306,
"user" = "myuser",
"password" = "mypassword"
“databaseName" = "xxx"),
Could someone tell me how to fix it?
Thanks a lot
You could create a user specially for your shiny application and give this user proper privileges. If you can access a terminal / MySQL workbench where you can type in SQL commands you could try:
Start by creating the user:
CREATE USER 'shinyuser'#'%' IDENTIFIED BY 'password123';
The create the database if necessary:
CREATE DATABASE MyDatabase;
And finally give permission to the new user:
GRANT ALL PRIVILEGES ON shinyuser.* TO 'MyDatabase'#'%' WITH GRANT OPTION;
This problem arises when your username and password is not matching with your database username and password. So please check your database username and password first then try it again.

Email sent from web server causes gmail to treat as phishing. How to get rid of this?

I am sending account activation email from my .net app.
I set the from address to "xyz.support#gmail.com" and from name "xyz" where xyz is the name of the domain i.e. our website.
It was not a problem when we were using Google's SMTP server as I provided credentials to google during sending. But now I am using my own web server's SMTP to send the email.
When I view the activation email in gmail, I get this:
This message may not have been sent by: xyz.support#gmail.com Learn more Report phishing
Is there a way to get rid of this so that gmail and other client don't show this message?
Here is the code:
var smtpClient = new SmtpClient();
var message = new MailMessage();
smtpClient.Host = _config.SMTPServer;
message.From = new MailAddress("xyz.support#gmail.com", "xyz");
message.To.Add("newuser#gmail.com");
message.IsBodyHtml = true;
message.Subject = "Test subject";
message.Body = "Test Body";
smtpClient.Send(message);
Thanks
The domain of the FROM address has to match the domain of the SMTP server that is sending the email, otherwise your message is treated as as spam.
This explains why you avoid the "error" by sending via Google's SMTP server.
The suggestion by IrishChieftain to use SPF helped me, so here is a summary of the steps I did:
1.) First, I also received emails in my GMail inbox that I sent from my sever and that got the "This message may not have been sent by..." warning.
2.) Next, I looked at the source of the email inside GMail (clicke the arrow next to the message and select "Display original"). An excerpt from there was:
Received-SPF: fail (google.com: domain of me#mydomain.com does not
designate 211.113.37.19 as permitted sender) client-ip=211.113.37.19;
So Google directly told me what to do: Add some SPF records in the DNS of my domain "mydomain.com" to get rid of this warning.
3.) Therefore I logged into the control panel of my DNS provider and added two TXT records, something like this:
*.mydomain.com. 180 v=spf1 +a +mx ip4:211.113.37.19 -all
mydomain.com. 180 v=spf1 +a +mx ip4:211.113.37.19 -all
Please note that I entered each line in three separate fields:
One field for *.mydomain.com.
One field for 180 (the TTL, 3 minutes in my example)
One field for v=spf1 +a +mx ip4:211.113.37.19 -all
4.) After that, I waited some time and tried to resend. This succeeded. Google now shows in the original:
Received-SPF: pass (google.com: domain of Received-SPF: pass (google.com: domain of me#mydomain.com designates 211.113.37.19 as permitted sender) client-ip=211.113.37.19;
Please note that I choose the SPF version since the mail server is on a different machine as the web server, so I could not perform the other solution as Mulmot wrote.
There is also an SPF Wizard from Microsoft to correctly generate SPF records. Alternatively, here is yet another SPF generator.

Resources