I am wanting to send an email to a gmail account from lua using the socket library.
smtp = require("socket.smtp")
address = { "<someone#gmail.com>" }
from = { "<someone#gmail.com>" }
theMessage = {
headers = {
to = "YOU",
cc = '"him" ',
subject = "I got something to tell you..."
},
body = "You're the best."
}
r, e = smtp.send{ from = from, rcpt = address, source = smtp.message(theMessage)}
When I do
print(e)
"connection refused".
print(r)
nil
Any ideas?
I'm just following instructions from the site:
http://w3.impa.br/~diego/software/luasocket/smtp.html
You may need to specify the ip/port in your smtp.send function
smtp.send{
from = from,
rcpt = address,
source = smtp.message(theMessage),
server = 127.0.0.1,
port = 25
}
Related
Using dovecot 2.3.7.2 with solr 8.11.2 when I do:
doveadm search -u user mailbox INBOX subject "something"
I get multiple mail ID's.
When I start a manual IMAP session and login as that user, select INBOX, and try the command:
. search subject "something"
It returns zero mail ID's; this is consistent across all searches using IMAP - no results returned, no matter what I search for in IMAP.
Further investigation shows that the SOLR search via doveadm is using just the 'username', whereas the IMAP search is using the full email address (and finding nothing).
Worse, with auto-update of the FTS turned on, the user-id used when updating as mail arrives is the domain-less user-id.
Is there a way to change this behaviour, or at least make it consistent?
The dovecot -n command returns:
# 2.3.7.2 (3c910f64b): /etc/dovecot/dovecot.conf
# Pigeonhole version 0.5.7.2 ()
# OS: Linux 5.4.0-125-generic x86_64 Ubuntu 20.04.5 LTS
# Hostname: WITHELD
mail_location = maildir:~/Mail
mail_plugins = " fts fts_solr virtual"
mail_privileged_group = mail
managesieve_notify_capability = mailto
managesieve_sieve_capability = fileinto reject envelope encoded-character vacation subaddress comparator-i;ascii-numeric relational regex imap4flags copy include variables body enotify environment mailbox date index ihave duplicate mime foreverypart extracttext
namespace {
location = virtual:~/Mail/virtual
prefix = virtual.
separator = .
}
namespace inbox {
inbox = yes
location =
mailbox Drafts {
special_use = \Drafts
}
mailbox Junk {
special_use = \Junk
}
mailbox Sent {
special_use = \Sent
}
mailbox "Sent Messages" {
special_use = \Sent
}
mailbox Trash {
special_use = \Trash
}
mailbox virtual.All {
comment = All my messages
special_use = \All
}
prefix =
}
passdb {
args = /etc/dovecot/dovecot-sql.conf.ext
driver = sql
}
passdb {
driver = pam
}
plugin {
fts = solr
fts_autoindex = yes
fts_enforced = yes
fts_solr = url=http://localhost:8983/solr/dovecot/
sieve = file:~/sieve;active=~/.dovecot.sieve
}
protocols = " imap lmtp sieve pop3 sieve"
service imap {
vsz_limit = 4 G
}
service index-worker {
vsz_limit = 2 G
}
service indexer-worker {
vsz_limit = 2 G
}
service lmtp {
inet_listener lmtp {
address = 127.0.0.1
port = 24
}
}
ssl_cert = </etc/letsencrypt/live/WITHELD/fullchain.pem
ssl_client_ca_dir = /etc/ssl/certs
ssl_dh = # hidden, use -P to show it
ssl_key = # hidden, use -P to show it
userdb {
args = /etc/dovecot/dovecot-sql.conf.ext
driver = sql
}
userdb {
driver = passwd
}
protocol lmtp {
mail_plugins = " fts fts_solr virtual sieve"
postmaster_address = WITHELD
}
protocol lda {
mail_plugins = " fts fts_solr virtual sieve"
}
protocol imap {
mail_max_userip_connections = 40
}
I'm building a so called 'Quickapp' in Home Center 3 (From Fibaro) in the 'Lua' programming language. I want to fetch some data from the Tado api, but it's poorly documented. I keep getting the following message from the console:
Full authentication is required to access this resourceunauthorized
I think that's because I need do assign the Bearer token from the request, but i'm a little lost how...
This is what i have so far:
function QuickApp:fetchTadoData(username,password,client_secret)
local url = "https://auth.tado.com/oauth/token"
local postdata = {
["client_id"] = "tado-web-app",
["grant_type"] = "password",
["scope"] = "home.user",
["username"] = username,
["password"] = password,
["client_secret"] = client_secret
}
local extraheaders = {
["content-type"] = "application/json"
}
self.http:request(url, {
options={
headers = extraheaders,
data = json.encode(postdata),
method = "POST"
},
success = function(status)
self:debug(status.data)
end,
error = function(error)
errorlog("Error getting data: "..error)
self:debug("hallo")
end
})
end
I know the Curl code to get the 'Bearer token' response:
curl -s "https://auth.tado.com/oauth/token" -d client_id=tado-web-app -d grant_type=password -d scope=home.user -d username="you#example.com" -d password="Password123" -d client_secret=wZa
But I don't know how to translate this to the above Lua code. Any help is appreciated!
https://manuals.fibaro.com/home-center-3-quick-apps
Looks OK, the main thing I'm noticing is this:
"self.http must have previously been created by net.HTTPClient"
function QuickApp :fetchTadoData( username, password, client_secret )
self .http = net .HTTPClient( { timeout = 5000 } ) -- 5 seconds
local url = "https://auth.tado.com/oauth/token"
local requestBody = {
action = 'create',
params = {
["client_id"] = "tado-web-app",
["grant_type"] = "password",
["scope"] = "home.user",
["username"] = username,
["password"] = password,
["client_secret"] = client_secret
}
}
local extraheaders = {
["content-type"] = "application/json",
["accept"] = "application/json"
}
self .http :request( url, {
options = {
headers = extraheaders,
data = json .encode( requestBody ),
method = "POST"
},
success = function( response )
self :debug( response .status )
self :debug( response .data )
end, -- success
error = function( msg )
self :debug( 'Error: ' ..msg )
end -- error
})
end -- :fetchTadoData()
I have set up a Service bus 1.1 for windows server and trying to access it using the following code.
var sbUriList = new List<Uri>() { new UriBuilder { Scheme = "sb", Host = ServerFQDN, Path = ServiceNamespace }.Uri };
var httpsUriList = new List<Uri>() { new UriBuilder { Scheme = "https", Host = ServerFQDN, Path = ServiceNamespace, Port = HttpPort }.Uri };
NetworkCredential credential = new NetworkCredential("<User Name>", "<Password>", "<Domain>");
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback((s, cert, chain, ssl) => { return true; });
TokenProvider tokenProvider = TokenProvider.CreateOAuthTokenProvider(httpsUriList, credential);
messageFactory = MessagingFactory.Create(sbUriList, tokenProvider);
ServiceBusConnectionStringBuilder connBuilder = new ServiceBusConnectionStringBuilder();
connBuilder.ManagementPort = HttpPort;
connBuilder.RuntimePort = TcpPort;
connBuilder.Endpoints.Add(new UriBuilder() { Scheme = "sb", Host = ServerFQDN, Path = ServiceNamespace }.Uri);
connBuilder.StsEndpoints.Add(new UriBuilder() { Scheme = "https", Host = ServerFQDN, Port = HttpPort, Path = ServiceNamespace }.Uri);
namespaceManager = NamespaceManager.CreateFromConnectionString(connBuilder.ToString());
if (!namespaceManager.QueueExists(queuename))
{
namespaceManager.CreateQueue(queuename);
}
this works fine if i run my code from a console application, but however if I put this in a windows service and run it under either a Local service or Local System the code throws the following exception while trying to check if the queue exists in the following line namespaceManager.QueueExists(queuename).
Unexpected exception : System.UnauthorizedAccessException: The remote server returned an error: (401) Unauthorized. Manage claim is required for this operation..TrackingId:5be1365e-b4ae-4555-b81b-dcbef96be9d0_GIE11LT32PD622,TimeStamp:4/19/2015 3:51:28 PM ---> System.Net.WebException: The remote server returned an error: (401) Unauthorized.
at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at Microsoft.ServiceBus.Messaging.ServiceBusResourceOperations.GetAsyncResult`1.<GetAsyncSteps>b__2d(GetAsyncResult`1 thisPtr, IAsyncResult r)
at Microsoft.ServiceBus.Messaging.IteratorAsyncResult`1.StepCallback(IAsyncResult result)
--- End of inner exception stack trace ---
Can someone please help me understand what I am doing wrong?
Finally found the issue in my code, thought i'll share it in case anyone else has the same issue.
my issue was that in the namespace I had not set the token as below:
namespaceManager.Settings.TokenProvider = tokenProvider;
as a result of which it was using the wrong token for connection and hence the error.
I am trying to send mail using Grails Async Mail API
When I tried for Gmail using below configuration :
grails {
mail {
host = "smtp.gmail.com"
port = 465
username = "xxxx#gmail.com"
password = "xxxx"
props = ["mail.smtp.auth":"true",
"mail.smtp.socketFactory.port":"465",
"mail.smtp.socketFactory.class":"javax.net.ssl.SSLSocketFactory",
"mail.smtp.socketFactory.fallback":"false"]
}
}
in config.groovy, I was able to send mail. When I changed above configuration for a specific mail server as below :
grails {
mail {
host = "xxx"
port = 25
username = "xxx"
props = ["mail.smtp.auth":"false",
"mail.smtp.socketFactory.port":"25",
"mail.smtp.socketFactory.class":"javax.net.ssl.SSLSocketFactory",
"mail.smtp.socketFactory.fallback":"true",
"mail.smtp.starttls.enable": "false",
"mail.smtp.starttls.required": "false"]
}
}
I am getting below error :
javax.mail.MessagingException: Could not connect to SMTP host: xxx, port: 25;
nested exception is:
javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
Please provide me some hint, what I am doing wrong in above case.
You can try to do simply following and it should work for you
grails {
mail {
host = "xxx"
port = 25
username = "xxx"
props = ["mail.smtp.auth":"false",
"mail.smtp.socketFactory.port":"25",
"mail.smtp.starttls.enable": "true"]
}
}
I have mvc web app sending an email when new user gets created with following code:
private static void SendMail(User user)
{
string ActivationLink = "http://localhost/Account/Activate/" +
user.UserName + "/" + user.NewEmailKey;
var message = new MailMessage("ashu#gmail.com", user.Email)
{
Subject = "Activate your account",
Body = ActivationLink
};
var client = new SmtpClient("localhost");
client.UseDefaultCredentials = false;
client.Send(message);
}
What's wrong with my code please tell me.
ERROR : Failure sending mail. {"Unable to connect to the remote server"}
Smtp configuration :
Here are the likely causes of this error:
1 You are not supplying the correct authentication details
2 The port is blocked, for example by a firewall
In your example, I notice you are not specifying the port when you create your SmtpClient - it may help to specify it.
Gmail opens in port 587, and u need to enable ssl.
Try following code.
var smtp = new SmtpClient
{
Host = "smtp.gmail.com",
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(<fromAddress>, <fromPassword>)
};
using (var message = new MailMessage(<fromAddress>, <toAddress>)
{
Subject = <subject>,
Body = <body>
})
{
smtp.Send(message);
}