I'm working on sending a notification email using Logstash if an error occurs.
I'm using the email plugin coming as part of logstash : http://logstash.net/docs/1.4.2/outputs/email
On checking the documentation the To address seems to be the only required field and it didn't work when i specified it to my gmail id : pjesudhas#gmail.com
Is it required to have any other mail server running in my system for this to work, if so what do i have to do. Please let me know your thoughts.
email{
options => [ "smtpIporHost", "smtp.gmail.com",
"port", "587",
"userName", "pjesudhas#gmail.com",
"password", "mypassword"
]
from => "pjesudhas#gmail.com"
subject => "Error status"
to => "pjesudhas#gmail.com"
body => "Here is the event line that occured: %{#message}"
htmlbody => "<h2>%{matchName}</h2><br/><br/><h3>Full Event</h3><br/><br/><div align='center'>%{#message}</div>"
}
I also tried including my gmail id settings based on reading a tutorial but it didn't work either,please help me on this.
Gmail SMTP requires the to and from addresses to use a specific format: <example#example.org>
Try
email{
options => [ "smtpIporHost", "smtp.gmail.com",
"port", "587",
"userName", "pjesudhas#gmail.com",
"password", "mypassword"
]
from => "<pjesudhas#gmail.com>"
subject => "Error status"
to => "<pjesudhas#gmail.com>"
body => "Here is the event line that occured: %{#message}"
htmlbody => "<h2>%{matchName}</h2><br/><br/><h3>Full Event</h3><br/><br/><div align='center'>%{#message}</div>"
}
Related
I am working with nodemailer to send email using custom SMTP server.
let transporter = nodemailer.createTransport({
host: 'my.smtp.host',
port: 587,
secure: false,
auth: {
user: 'user',
pass: 'password',
},
debug: true,
logger: true
})
let info = await transporter.sendMail({
from: from,
to: to,
subject: subject,
text: content,
html: content,
cc: cc,
bcc: bcc,
})
Following is the result of sendMail.
{
accepted: [
'to#to.com'
],
rejected: [],
envelopeTime: 39,
messageTime: 49,
messageSize: 1730,
response: '250 2.0.0 Ok: queued as 5513B432BE6',
envelope: {
from: 'from#from.com',
to: [
'to#to.com'
]
},
messageId: '<274421c8-1abd-4973-dd8e-f57285b46a70#from.com>'
}
And following is log message.
...
[2021-06-09 19:00:21] INFO [StdWZWNkAto] <1730 bytes encoded mime message (source size 1693 bytes)>
[2021-06-09 19:00:21] DEBUG [StdWZWNkAto] S: 250 2.0.0 Ok: queued as 5513B432BE6
[2021-06-09 19:00:21] DEBUG [StdWZWNkAto] Closing connection to the server using "end"
I already tested this SMTP server with other tools and it works correctly.
What's wrong?
Please help me.
Well, this means that nodemailer successfully send the email and now it is in the queue of your custom SMTP server, so you have to deal with it. For instance, sendmail allows to see the queue via mailq command and resend via sendmail -q (or sendmail -q -v for more information). If you need more details, you should provide info about your SMTP server.
I'm getting an exception while connecting to PostgreSQL 12 by creating a data source via wildfly admin console.
It works fine on my another machine which has PostgreSQL 9.5. and it seems to work fine when I connect without data-source.
try (Connection conn = DriverManager.getConnection(
"jdbc:postgresql://127.0.0.1:5432/registrar", "postgres", "postgres")) {
if (conn != null) {
System.out.println("Connected to the database!");
Statement statement = conn.createStatement();
ResultSet rs = statement.executeQuery("Select * FROM public.user LIMIT 10");
while(rs.next())
System.out.println(rs.getString(2));
} else {
System.out.println("Failed to make connection!");
}
But when I create a data-source like this:
and this the exception that I get when I try to test the connection from UI.
Request
{
"address" => [
("subsystem" => "datasources"),
("data-source" => "RegistrarDS")
],
"operation" => "test-connection-in-pool"
}
Response
Internal Server Error
{
"outcome" => "failed",
"failure-description" => "WFLYJCA0040: failed to invoke operation: WFLYJCA0047: Connection is not valid",
"rolled-back" => true,
"response-headers" => {"process-state" => "reload-required"}
}
Has anything changed in PostgreSQL 12? What could be the issue?
Could be an issue with the datasource-class defined in your driver as described here on issues.redhat.com
If a datasource-class is defined then it takes precedence to create the datasource and as such it can only use connection-properties.
Since there is not a single connection-url property for all drivers, you have to use connection-properties if you are defining the datasource-class.
Another thing you could try is to set "Connection Properties" instead of "Connection URL" and make sure you are using the correct/latest driver jar file.
Also check your Postgresql logs for further info on the exception..
-> https://www.postgresql.org/about/news/2000/
I am trying to send an email using Google's Business email Account.
I am using Grails 3.2.7 and Grails's mail plugin ('org.grails.plugins:mail:2.0.0.RC6').
I am getting the following exception, even though I have set all the authentication credentials and I have set my account to allow less secure apps to access.
org.springframework.mail.MailAuthenticationException: Authentication failed; nested exception is javax.mail.AuthenticationFailedException
Following are the settings for sending mail
mail {
host = 'smtp.gmail.com'
port = 587
username = "##### BUSINESS EMAIL from GMAIL###"
password = "PASSWORD"
props = ["mail.smtp.auth" : "true",
"mail.smtp.socketFactory.port" : "465",
"mail.smtp.socketFactory.class" : "javax.net.ssl.SSLSocketFactory",
"mail.smtp.socketFactory.fallback": "false"]
}
Anyone can help on why is it not sending email and failing on Authentication.
Please note that if I try to send the email using normal GMAIL account with same settings it is working fine.
Additional information
I am trying to send email to other domains from sender email being "BUSINESS EMAIL from GMAIL"
I have sent mail using Grails 3.1.8 and dependency
compile "org.grails.plugins:mail:2.0.0.RC2".
You can try it in grails 3.2.7
mail {
host = "smtp.gmail.com"
port = 465
username = "test#gmail.com"
password = "password"
ssl = "on"
props = ["mail.smtp.auth" : "true",
"mail.smtp.port" : "465",
"mail.smtp.socketFactory.port" : "465",
"mail.smtp.socketFactory.class" : "javax.net.ssl.SSLSocketFactory",
"mail.imap.ssl.checkserveridentity": "false",
"mail.imap.ssl.trust" : "*",
"mail.smtp.socketFactory.fallback" : "true"]
}
In in a POC I got the Smtp client to send emails through Gmail, so I know my information regarding connecting to Gmail's SMTP server is correct. I am now trying to configure Serilog through appsettings.json to send my log entries through Gmail. I need to be able to configure it different for different environments. I currently have it set to Verbose so that I get anything...it won't be that way later. I am not getting anything but my file log entry. I had this working with a local network SMTP server that took defaults and no network credentials. Now I need to set the port, ssl, and network credentials to be able to send through Gmail.
Here is my WriteTo section...
"WriteTo": [
{
"Name": "RollingFile",
"Args": {
"pathFormat": "C:/log/log-{Date}.json",
"formatter": "Serilog.Formatting.Json.JsonFormatter, Serilog",
"fileSizeLimitBytes": 2147483648,
"retainedFileCountLimit": 180,
"restrictedToMinimumLevel": "Verbose"
}
},
{
"Name": "Email",
"Args": {
"connectionInfo": {
"FromEmail": "{email address}",
"ToEmail": "{email address}",
"MailServer": "smtp.gmail.com",
"EmailSubject": "Fatal Error",
"NetworkCredentials": {
"userName": "{gmailuser}#gmail.com",
"password": "{gmailPassword}"
},
"Port": 587,
"EnableSsl" : true
},
"restrictedToMinimumLevel": "Verbose"
}
}
]
},
Any help is appreciated.
Change your port number to 465 and it should work for you. Here's a some info on gmail smtp settings: https://www.lifewire.com/what-are-the-gmail-smtp-settings-1170854
I'm using Core 2.0 and couldn't get the serilog email sink to work with the appsettings.json file, but I do have it working by setting the configs in the program.cs file like so:
var logger = new LoggerConfiguration()
.WriteTo.RollingFile(
pathFormat: "..\\..\\log\\AppLog.Web-{Date}.txt",
outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] [{SourceContext}] [{EventId}] {Message}{NewLine}{Exception}"
)
.WriteTo.Email(new EmailConnectionInfo
{
FromEmail = appConfigs.Logger.EmailSettings.FromAddress,
ToEmail = appConfigs.Logger.EmailSettings.ToAddress,
MailServer = "smtp.gmail.com",
NetworkCredentials = new NetworkCredential {
UserName = appConfigs.Logger.EmailSettings.Username,
Password = appConfigs.Logger.EmailSettings.Password
},
EnableSsl = true,
Port = 465,
EmailSubject = appConfigs.Logger.EmailSettings.EmailSubject
},
outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] {Message}{NewLine}{Exception}",
batchPostingLimit: 10
, restrictedToMinimumLevel: Serilog.Events.LogEventLevel.Error
)
.CreateLogger();
appsettings won´t work for Serilog.Synk.Email if you need NetworkCredentials. It will raise this exception: System.InvalidOperationException: 'Cannot create instance of type 'System.Net.ICredentialsByHost' because it is either abstract or an interface.'. Use #rcf113 answer to make thing work.
To make things work with your gmail account, you have to:
EnableSsl: true
Port: 465
Create app password
To make appsettings work, you'll have to come up with a custom implementation. This solution was given from #adriangutowski github answer
Create a custom static extension class to instance a NetworkCredential for ICredentialsByHost property
namespace MyWebApi.Extensions
{
public static class SerilogCustomEmailExtension
{
const string DefaultOutputTemplate = "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] {Message}{NewLine}{Exception}";
public static LoggerConfiguration CustomEmail(
this LoggerSinkConfiguration loggerConfiguration,
CustomEmailConnectionInfo connectionInfo,
string outputTemplate = DefaultOutputTemplate,
LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum
)
{
return loggerConfiguration.Email(
connectionInfo,
outputTemplate,
restrictedToMinimumLevel
);
}
public class CustomEmailConnectionInfo : EmailConnectionInfo
{
public CustomEmailConnectionInfo()
{
NetworkCredentials = new NetworkCredential();
}
}
}
}
Then configure your appsettings Serilog.Using with your assembly name (not namespace) and add a new entry to Serilog.WriteTo[]
"Serilog": {
"Using": [ "Serilog.Sinks.Email", "MyWebApi" ],
"MinimumLevel": "Error",
"WriteTo": [
{
"Name": "CustomEmail",
"Args": {
"ConnectionInfo": {
"NetworkCredentials": {
"UserName": "aaaaaaaaaaaaaa#gmail.com",
"Password": "aaaaaaaaaaaaaa"
},
"FromEmail": "aaaaaaaaaaaaaa#gmail.com",
"MailServer": "smtp.gmail.com",
"EmailSubject": "[{Level}] Log Email",
"Port": "465",
"IsBodyHtml": false,
"EnableSsl": true,
"ToEmail": "aaaaaaaaaaaaaa#gmail.com"
},
"RestrictedToMinimumLevel": "Error",
"OutputTemplate": "{Timestamp:yyyy-MM-dd HH:mm} [{Level}] {Message}{NewLine}{Exception}"
}
}
]
}
This configuration worked fine using
Dotnet Core 6
Serilog.Sinks.Email Version="2.4.0"
I am getting the below error while sending a mail Via Logstash email plugin ,
←[31mSomething happen while delivering an email {:exception=>#<Net::SMTPAuthenticationError: 504 5.7.4 Unrecognized authentication type
Below is my Logstash Confifuration for email plugin :
email {
from => "mymail#domain.com"
options => [ "smtpIporHost", "my ip",
"port", "25",
"userName", "mymail#domain.com",
"password", "password"
]
via => "smtp" # or pop or sendmail
subject => "Alert from Logstash"
body => "Here is the event line %{#message}"
htmlbody => "<h2></h2><br/><br/><h3>Full Event</h3><br/><br/><div align='center'>%{#message}</div>"
}
But when I use JAVA client (a java program) to send a mail, I am able to send a mail but cannot reciprocate with Logstash.
Am I missng any configuration ? to avoid the above error
I don't know what exactly email plugin version you are using in your logstash, but you should add:
authentication => "login"