Send email to many addresses in gradle using ant - ant

I would like to send an email to many addresses using Ant in Gradle, but I don't know how to do this, I implemented a gradle script to send emails to a single address
task sendMail << {
configurations.mail.each { File jar ->
org.apache.tools.ant.Project.class.classLoader.addURL( jar.toURI().toURL() )
}
def mailParams = [
mailhost: 'myhost',
mailport: 25,
subject: "subject",
messagemimetype: "text/plain"
]
ant.mail( mailParams ) {
from( address:'mymail1#hotmail.es' )
to( address:'mymail2#hotmail.es' )
message( "So far, so good" )
}
}
this implementation work fine to send to a single address, how can I send to many addresses?

You might find help here: How to Send email by using Ant Mail.

Related

How do I get the JSON response from Dialogflow with Rails?

I understand the whole process of dialogflow and I have a working deployed bot with 2 different intents. How do I actually get the response from the bot when a user answers questions? (I set the bot on fulfillment to go to my domain). Using rails 5 app and it's deployed with Heroku.
Thanks!
If you have already set the GOOGLE_APPLICATION_CREDENTIALS path to the jso file, now you can test using a ruby script.
Create a ruby file -> ex: chatbot.rb
Write the code bellow in the file.
project_id = "Your Google Cloud project ID"
session_id = "mysession"
texts = ["hello"]
language_code = "en-US"
require "google/cloud/dialogflow"
session_client = Google::Cloud::Dialogflow::Sessions.new
session = session_client.class.session_path project_id, session_id
puts "Session path: #{session}"
texts.each do |text|
query_input = { text: { text: text, language_code: language_code } }
response = session_client.detect_intent session, query_input
query_result = response.query_result
puts "Query text: #{query_result.query_text}"
puts "Intent detected: #{query_result.intent.display_name}"
puts "Intent confidence: #{query_result.intent_detection_confidence}"
puts "Fulfillment text: #{query_result.fulfillment_text}\n"
end
Insert your project_id. You can find this information on your agent on Dialogflow. Click on the gear on the right side of the Agent's name in the left menu.
Run the ruby file in the terminal or in whatever you using to run ruby files. Then you see the bot replying to the "hello" message you have sent.
Obs: Do not forget to install the google-cloud gem:
Not Entirely familiar with Dilogflow, but if you want to receive a response when an action occurs on another app this usually mean you need to receive web-hooks from them
A WebHook is an HTTP callback: an HTTP POST that occurs when something happens; a simple event-notification via HTTP POST. A web application implementing WebHooks will POST a message to a URL when certain things happen.
I would recommend checking their fulfillment documentation for an example. Hope this helps you out.

Ruby mail gem - search inbox from specific email addresses

Does anybody know how to get mail from an array of email addresses using the 'mail' gem in Ruby? I've seen the thread for getting unread messages like so:
new_messages = Mail.find(keys: ['NOT','SEEN'])
But I cannot find how to get messages from a certain address. I've tried:
new_messages = Mail.find(keys: ['FROM','example#hello.com'])
but it doesn't work.
I know section 6.4.4 of the IMAP protocol indicates the different search flags you can use to search for messages, but I can't seem to make it work.
Unfortunately, neither
Mail.find( keys: ['FROM', from_address] )
nor
Mail.find( keys: "FROM #{from_address}" )
worked. What worked, however, is quoting the email address:
Mail.find( keys: "FROM \"#{from_address}\”" )
Luckily, it was just the missing quotes, as the array variant works as well when quoting the email address:
Mail.find( keys: ['FROM', "\"#{from_address}\”"] )
Try this for single email address
Mail.all.select { |mail| mail.from.addresses.include?('example#hello.com') }
And for multiple try this
addresses = ['example#hello.com', 'test#hello.com']
Mail.all.select { |mail| (addresses - mail.from.addresses).empty? }
Also if you want to find just first mail try this
Mail.all.find { |mail| mail.from.addresses.include?('example#hello.com') }

Grails mail plugin send from differnet emails

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.

Grails Send Mail is not working

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.

While processing an email reply how can I ignore any email client specifics & the history?

I have a rails application which processes incoming emails via IMAP. Currently a method is used that searches the parts of a TMail object for a given content_type:
def self.search_parts_for_content_type(parts, content_type = 'text/html')
parts.each do |part|
if part.content_type == content_type
return part.body
else
if part.multipart?
if body = self.search_parts_for_content_type(part.parts, content_type)
return body
end
end
end
end
return false
end
These emails are generally in response to a html email it sent out in the first place. (The original outbound email is never the same.) The body text the method above returns contains the full history of the email and I would like to just parse out the reply text.
I'm wondering whether it's reasonable to place some '---please reply above this line---' text at the top of the mail as I have seen in a 37 signals application.
Is there another way to ignore the client specific additions to the email, other than write a multitude of regular expressions (which I haven't yet attempted) for each and every mail client? They all seem to tack on their own bit at the top of any replies.
I have to do email reply parsing on a project I'm working on right now. I ended up using pattern matching to identify the response part, so users wouldn't have to worry about where to insert their reply.
The good news is that the implementation really isn't too difficult. The hard part is just testing all the different email clients and services you want to support and figuring out how to identify each one. Generally, you can use either the message ID or the X-Mailer or Return-Path header to determine where an incoming email came from.
Here's a method that takes a TMail object and extracts the response part of the message and returns that along with the email client/service it was sent from. It assumes you have the original message's From: name and address in the constants FROM_NAME and FROM_ADDRESS.
def find_reply(email)
message_id = email.message_id('')
x_mailer = email.header_string('x-mailer')
# For optimization, this list could be sorted from most popular to least popular email client/service
rules = [
[ 'Gmail', lambda { message_id =~ /.+gmail\.com>\z/}, /^.*#{FROM_NAME}\s+<#{FROM_ADDRESS}>\s*wrote:.*$/ ],
[ 'Yahoo! Mail', lambda { message_id =~ /.+yahoo\.com>\z/}, /^_+\nFrom: #{FROM_NAME} <#{FROM_ADDRESS}>$/ ],
[ 'Microsoft Live Mail/Hotmail', lambda { email.header_string('return-path') =~ /<.+#(hotmail|live).com>/}, /^Date:.+\nSubject:.+\nFrom: #{FROM_ADDRESS}$/ ],
[ 'Outlook Express', lambda { x_mailer =~ /Microsoft Outlook Express/ }, /^----- Original Message -----$/ ],
[ 'Outlook', lambda { x_mailer =~ /Microsoft Office Outlook/ }, /^\s*_+\s*\nFrom: #{FROM_NAME}.*$/ ],
# TODO: other email clients/services
# Generic fallback
[ nil, lambda { true }, /^.*#{FROM_ADDRESS}.*$/ ]
]
# Default to using the whole body as the reply (maybe the user deleted the original message when they replied?)
notes = email.body
source = nil
# Try to detect which email service/client sent this message
rules.find do |r|
if r[1].call
# Try to extract the reply. If we find it, save it and cancel the search.
reply_match = email.body.match(r[2])
if reply_match
notes = email.body[0, reply_match.begin(0)]
source = r[0]
next true
end
end
end
[notes.strip, source]
end
I think you will be stuck on this one. I have been doing some stuff with emails myself in TMail recently, and what you will generally find is that an email that has an HTML part is generally structured like:
part 1 - multipart/mixed
sub part 1 - text/plain
sub part 2 - text/html
end
The email clients I have played with Outlook and Gmail both generate replies in this format, and they just generally quote the original email inline in the reply. At first I though that the 'old' parts of the original email would be separate parts, but they are actually not - the old part is just merged into the reply part.
You could search the part for a line that begins 'From: ' (as most clients generally place a header at the top of the original email text detailing who sent it etc), but its probably not guaranteed.
I don't really see anything wrong with a --- please reply above this line --- generally, its not that invasive, and could make things a lot simpler.

Resources