I am using Mail Plugin to send email in my grails application. I am doing like this ...
Config.groovy ----
grails {
mail {
host = "smtp.gmail.com"
port = 465
username = "example#gmail.com"
password = "*********"
props = ["mail.smtp.auth":"true",
"mail.smtp.socketFactory.port":"465",
"mail.smtp.socketFactory.class":"javax.net.ssl.SSLSocketFactory",
"mail.smtp.socketFactory.fallback":"false"]
} }
and Controller ---
class MailController {
def mailService
def sendmail = {
mailService.sendMail {
to "example#gmail.com"
subject "Hello Fred"
body 'How are you?'
}
}
When I am trying to send mail. It throwing ERROR
URI
/groovypublish/mail/sendmail
Class
sun.security.provider.certpath.SunCertPathBuilderException
Message
unable to find valid certification path to requested target
If I remove mail props part from my config.groovy. Then After send mail, my page loaded infinite times.
I am using localhost:8080 to send mail. I know problem is in SSL. But How can I avoid SSL part.
Please help ...
I had the same issue. Going into my virus scanner's settings and turning off outbound mail scanning solved the issue.
Related
I was using smtp server with Username password to send mail using the below function.
def sendEmail() {
AsynchronousMailMessage message = asyncMailService.sendMail {
// Mail parameters
to appointmentDetails.emailAddress
from AppConstant.EMAIL_SENDER
subject emailSubject
html emailMessage
}
}
SMTP details are stored in application.groovy.
grails {
mail {
host = "smtp.gmail.com"
port = 465
username = "XXXXXXXXXXXX#gmail.com"
password = "XXXXXXXXX"
props = ["mail.smtp.auth":"true",
"mail.smtp.socketFactory.port":"465",
"mail.smtp.socketFactory.class":"javax.net.ssl.SSLSocketFactory",
"mail.smtp.socketFactory.fallback":"false"]
}
}
So this was working fine. Now our team wants to use SendGrid for achieve sending mails. I have got the API key, Key Name and other details from SendGrid Team and also have whitelisted my IP in sendGrid configuration. How can i implement that?
Have added below config in application.yml
sendgrid:
api: '${SENDGRID_APIKEY}'
from: '${SENDGRID_FROM_EMAIL}'
i'm using Grails 2.5.1 and mail:1.0.7 plugin to send emails , but when i'm using it i always getting the bellow error :
Class:javax.mail.AuthenticationFailedExceptionMessage:535-5.7.8 Username and Password not accepted. Learn more at 535 5.7.8 https://support.google.com/mail/answer/14257 qq4sm4579366wjc.14 - gsmtp
although i can login with the provided credentials successfully from the browser !!
here are my configurations in the Config file :
grails {
mail {
host = "smtp.gmail.com"
port =465
username = "****"
password = "***"
props = ["mail.smtp.auth":"true",
"mail.smtp.socketFactory.port":"465",
"mail.smtp.socketFactory.class":"javax.net.ssl.SSLSocketFactory",
"mail.smtp.socketFactory.fallback":"false"]
}
}
and here is the action :
mailService.sendMail{
to userInstance.toEmail
subject userInstance.subject
html "<strong>Test</strong> "
}
anything i'm missing ?
It may be because of gmail's security feature for less secure apps to get authenticated. Just turn on the access for less secure apps.
Follow below steps:
1 Login to your gmail account
2 Access the url:
https://www.google.com/settings/security/lesssecureapps
3 Select "Turn on"
If you have gmail - settings for plugin are correct (i have the same and they are working) , but if your email is not gmail you must have other config.
By the way if you gmail :
Username and Password not accepted.
your username or password is wrong, try to login with this Username and password, watch out for register of letters.
https://grails.org/plugin/mail
I have a list of persons with individual emails (on different kind of mail services, for example gmail and hotmail). I want to send mail from their respective email addresses, like this:
mailService.sendMail {
from "hereMail#some.com"
}
In order to send mail I must set the configuration in Config.groovy. Should I maintain all emails configuration in Config.groovy file? or some other solution exist for this problem?
The configuration only allows the sending from one SMTP server. The account that sends the email is not necessarily the "from" address even though it is being emailed from that account. You should be able to use one account as the SMTP server and change the "from" as needed.
The configuration item sets the "default" from address for outgoing messages. The plugin provides a DSL that is used to specify the components of the message, including a specific From address if you want. If you don't provide a from specification in the message DSL, then it uses the configuration specified value.
Here is a snippet of code that I use in my messaging system to set a user account supplied from address on outgoing messages:
mailMessage = mailService.sendMail {
multipart true
if (toAddresses) { to toAddresses }
if (ccAddresses) { cc ccAddresses }
if (bccAddresses) { bcc bccAddresses }
from messageSpecification.from
subject messageSpecification.subject
if (messageSpecification.plainText) { text messageSpecification.plainText }
if (messageSpecification.htmlText) { html messageSpecification.htmlText }
messageSpecification.attachments.each {
attach(it.filename, it.mediaType, it.data)
}
}
Simply replace the messageSpecification.from reference to your specific from address and you are good to go.
i am new to Grails.
i am using mail 1.0 pluguin..
i configured config file as below
grails {
mail {
host = "smtp.gmail.org"
port = 465
username = "myaccount#gmail.com"
password = "mypassword"
props = ["mail.smtp.auth":"true",
"mail.smtp.socketFactory.port":"465",
"mail.smtp.socketFactory.class":"javax.net.ssl.SSLSocketFactory",
"mail.smtp.socketFactory.fallback":"false"]
}
}
and used sendMail() in controller as below
sendMail {
to "myanotheraccount#gmail.com"
subject "New User Confirmation"
body "how are u"
}
I have no firewall issues.
but it show s error as Connection refused.......???
Probably a configuration issue, have you looked at this example which shows how to use Mailgun via SMTP: https://github.com/jbayer/mail-java
I'm trying to send email using asp.net mvc application. Smtp client is configured in web.config e.g.:
<mailSettings>
<smtp from="noreply#test.sk">
<network host="mail.test.sk" defaultCredentials="false" userName="noreply#test.sk" password="pass" port="25"/>
</smtp>
</mailSettings>
C#:
using (SmtpClient client = new SmtpClient())
{
MailMessage message = new MailMessage(from, to, subject, body);
client.Timeout = 10000;
client.Send(message);
return false;
}
The thing is, it doesn't work (I get timeout exception) until I try to send email using outlook. Right after sending email by outlook it successfully sends it also by my web application. Is there some special kind of authentication which outlook is doing which then allows all emails from my IP to be authenticated?? What is the reason it works only after sending it by outlook?
BTW:
I'm running the application in VS asp.net development server. When I deploy it to webhosting server, it doesn't work (timeout).
My webhosting provider told me there is a classic smtp authentication on that server (not pop3 before smtp).
EDITED:
I figured out, when it worked and I tried it by telnet or traced it by wireshark, the communication started by:
220 mail2.hostmaster.sk ESMTP Postfix
EHLO fernet-PC
250-mail2.hostmaster.sk
250-PIPELINING
250-SIZE 104857600
250-ETRN
250-STARTTLS
250-AUTH PLAIN LOGIN
250-AUTH=PLAIN LOGIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
...
Compared to when it didn't work (just tried a day before), the whole communication looked like:
220-mail2.hostmaster.sk ESMTP Postfix
EHLO fernet-PC
250-mail2.hostmaster.sk
250-SIZE 104857600
250-ETRN
250-STARTTLS
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
So there is a difference in supported auth methods and support for pipelining. I guess that System.Net.Mail.SmtpClient then doesn't know which authentication method should it use and so it stucks and therefore I'm getting the timeout exception.
That's interesting that outlook has no problems to connect and send email.
I solved my problem by not using their smtp server, as I'm running out of time. I'm using gmail's smtp server instead. I created new gmail account where I set alias to what I needed, so the email looks like it didn't come from gmail on the first look.
I have fixed a similar problem on a site and came across this Question while researching the issue.
The code below works for Google Apps for Business;
public class SendSMTPEmail
{
public static void SendText(string ToName, string ToEmail, string FromName, string FromEmail, string Subject, string Content)
{
MailAddress from = new MailAddress(ToEmail, ToName);
MailAddress to = new MailAddress(ToEmail, ToName);
var smtp = new SmtpClient
{
Host = "smtp.gmail.com",
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
Credentials = new NetworkCredential("username#googlemail.com", "yourpassword"),
Timeout = 20000
};
MailMessage message = new MailMessage()
{
From = from,
Body = Content,
Subject = Subject
};
message.To.Add(to);
smtp.Send(message);
}
}
Does this help?