I want a single sending address to use a different gmail account, and all others to use the default gmail account.
As most tutorials online say this should work, but postfix uses the default smtp user name and password for all emails...
Is there any documentation for postfix that can help?
Sender dependent tls encryption also appears to not be an option... am I wrong?
### main.cf ###
relayhost = smtp.gmail.com:587
smtp_sasl_auth_enable=yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_password
sender_dependent_relayhost_maps=/etc/postfix/senderDependentRelayHostMap
smtp_use_tls = yes
smtp_sasl_security_options = noanonymous
smtp_sasl_tls_security_options = noanonymous
smtp_tls_note_starttls_offer = yes
smtp_tls_...
### senderDependentRelayHostMap ###
test#gmail.com smtp.gmail.com:587
### sasl_password ###
#per sender email stmp username and password
test#gmail.com test#gmail.com:testPass
#default route
smtp.gmail.com:587 default#site.com:defaultPass
You have to configure Sender-Dependent SASL authentication in Postfix. Please add the following lines to your main.cf
#/etc/postfix/main.cf
#...
smtp_sender_dependent_authentication = yes
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = regexp:/etc/postfix/sasl_passwd
relayhost = smtp.gmail.com:587
smtp_tls_security_level = may
smtp_sasl_security_options =
#...
and create /etc/postfix/sasl_passwd with the following content.
/^test#gmail.com$/ test#gmail.com:testPass
/^/ default#site.com:defaultPass
Reload postfix.
If you send a mail to someone#yahoo.com from test#gmail.com using the following command
echo "Hi Everyone"|mail -s "Test email" -r "test#gmail.com" someone#yahoo.com
then your postfix server will authenticate using test#gmail.com's password configured in /etc/postfix/sasl_passwd. Mails from all other senders will authenticate using default#site.com:defaultPass
Ref: Postfix docs
Hope that helps.
Related
I'm trying to send emails using R, which will eventually be deployed in a Shiny application. I've got an Office 365 account which is able to send email if I log into it but using the SMTP server I'm not getting any connection so far.
I've tried packages mailR & emayili but I'm not getting anywhere for some reason. I've used our local mail server before and that worked but that won't work for a shiny deployment.
According to Outlook I'm supposed to use:
Server name: smtp.office365.com
Port: 587
Encryption method: STARTTLS
But I can't seem to find a package that can do STARTTLS encryption. For other mail providers I see the advice to turn on "less secure apps" but that's not an option for us.
Example code :
library(mailR)
send.mail(from = "Me#companydomain.com",
to = c("you#companydomain.com"),
subject = "Test",
body = "TEST",
smtp = list(host.name = "smtp.office365.com",
port = 587,
user.name = "Me#companydomain.com",
passwd = "SuperSecretPassword",
tls = TRUE),
authenticate = TRUE,
send = TRUE,
debug = TRUE)
# Another option, with emayili:
library(emayili)
smtp <- server(host = "smtp.office365.com",
port = 587,
username = "Me#companydomain.com",
password = "SuperSecretPassword")
email <- envelope(from = "Me#companydomain.com",
to = "you#companydomain.com",
subject = "This is a plain text message!",
text = "Hello!")
smtp(email, verbose = TRUE)
I really hope someone figured out a package that can use STARTTLS or how to encrypt in that way using one of these packages!
Best Regards,
Bob
I am developing an application in R and it needs to send the email to specific people in the organization.
sender <- "xxxx.yyyy#gmail.com"
recipients <- c("yyyy.xxxx#zzz.com")
send.mail(from = sender,
to = recipients,
subject = "Test mail from Rstudio",
body = "Test email body",
smtp = list(host.name = "smtp.gmail.com", port = 465,
user.name = "xxxx.yyyy#gmail.com",
passwd = "******", ssl = TRUE),
authenticate = TRUE,
send = TRUE)
This code works well when the sender sends a mail from gmail account. What can be done to send a email from a non gmail account (Organization email account)? Is it possible?
Thanks in advance...
if your app runs in a linux box, and the mail subsystem is properly configured:
system("echo 'test body' | mail -s 'test subject' -r sender_addr#foo.com dest_addr#bar.com")
I'm trying to use Migadu as an email host for my server but when I test postfix using sendmail I get the error
550 From header does not match login user
I have these settings in main.cf
relayhost = [smtp.migadu.com]:587
smtpd_sasl_auth_enable = yes
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options =
smtpd_tls_security_level = encrypt
smtp_use_tls = yes
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt
And I have this in my sasl_passwd file
[smtp.migadu.com]:587 postmaster#mydomain.com:password
Can someone help me find out what's causing the error?
Figured this out for anyone still looking ...
In Laravel's mail.php config file, find the section on the Global "From" Address.
/*
|--------------------------------------------------------------------------
| Global "From" Address
|--------------------------------------------------------------------------
|
| You may wish for all e-mails sent by your application to be sent from
| the same address. Here, you may specify a name and address that is
| used globally for all e-mails that are sent by your application.
|
*/
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'hello#example.com'),
'name' => env('MAIL_FROM_NAME', 'Example'),
],
You have to change hello#example.com to your email login for migadu. It worked for me after that.
When I retrieve messages (with imap) the folder /home/user/mail is created while my config files (postfix and dovecot) redirects to /home/user/Maildir folder, and Maildir folder contains emails I want to get with imap !
I made a symbolic link between these folders and now with android I can retrieve messages stored in strange folders. With ThunderBird I can not explore folders. I see that dovecot creates an .imap folder where messages are finally stored, but not like expected.
Does somebody knows the mistake I did ?
Best Regards
It was due to a bad dovecot config !
Lines added to /etc/dovecot/dovecot.conf :
ssl = yes
auth_mechanisms = plain login
mail_location = maildir:~/Maildir
passdb {
args = dovecot
driver = pam
}
protocols = imap
service auth {
unix_listener /var/spool/postfix/private/auth {
group = postfix
mode = 0660
user = postfix
}
}
ssl_cert = </etc/ssl/certs/ssl-cert-snakeoil.pem
ssl_key = </etc/ssl/private/ssl-cert-snakeoil.key
userdb {
driver = passwd
}
I'm trying to send emails from R using sendmailR package using the following code, which unfortunately fails :
## Set mail contents
from <- sprintf('<sendmailR#%s>', Sys.info()[4])
to <- '<slackline#gmail.com>'
subject <- 'Feeding Plots'
body <- list('Latest feeding graph', mime_part(feeding.plot,
name = "feeding"))
## Set control parameters
control <- sendmail_options(verboseShow = TRUE,
smtpServer ="smtp.gmail.com",
smtpPort = 587,
smtpSTARTTLS = '',
blocking = FALSE)
sendmail(from,
to,
subject,
msg = body,
control = control,
headers)
<< 220 mx.google.com ESMTP xt1sm884721wjb.17 - gsmtp
>> HELO kimura
<< 250 mx.google.com at your service
>> MAIL FROM: <sendmailR#kimura>
<< 530 5.7.0 Must issue a STARTTLS command first. xt1sm884721wjb.17 - gsmtp
Error in wait_for(code) :
SMTP Error: 5.7.0 Must issue a STARTTLS command first. xt1sm884721wjb.17 - gsmtp
The sendmailR manual doesn't mention how to configures STARTTLS although it does indicate that additional arguments can be passed, which is why I have included the option smtpSTARTLS = '' based on whats mentioned in some other threads (here and here). I've tried playing with the argument for smtpSTARTTLS and setting it to TRUE but no joy.
Any pointers to documentation or solutions would be most welcome.
Thanks
As far as I understand it, sendmailR doesn't support any type of login to the SMTP server, hence, gmail is basically unusable. You can only use the package if you are within the right network and set up a server that is only reachable within the network I guess (i.e., one NOT using authentication).
The alternative is the mail package (in which you cannot use your own address).
The reference from the sendmailR documentation is:
SMTP AUTH is currently unsupported.
You could give the new mailR package a shot that allows SMTP authorization: http://cran.r-project.org/web/packages/mailR/index.html
The following call should then work:
send.mail(from = "slackline#gmail.com",
to = "slackline#gmail.com",
subject = "Subject of the email",
body = "Body of the email",
smtp = list(host.name = "smtp.gmail.com", port = 465, user.name = "slackline", passwd = "PASSWORD", ssl = TRUE),
authenticate = TRUE,
send = TRUE)