I have a token that I am creating for a "ticket" in my app, I'd like to send this token in the from address or the reply to address.
I'm trying this
from = "oursupport+"+ticket.token+"#gmail.com"
mail(:from => from, :to => ticket.email, :subject => "Welcome to Support")
When I check the sent email, I cannot see the token added to the from address but it does send correctly.
Related
I am reading this tutorial where it teaches to build a contact-us form. Everything worked fine, But I think the following line is not working properly.
in inquiry.rb
def deliver
return false unless valid?
Pony.mail({
**:from => %("#{name}" <#{email}>),**
:subject => "feedback",
:body => message,
:html_body => simple_format(message)
})
end
the email is being sent by and to the same email address. Please Help.
Maybe you are using the gmail SMTP server. It has many disadvantages such as limited number of messages for a period. You can use smtp.mandrillapp.com instead of smtp.gmail.com.
I have a system which receives and send mails to the various members in a group.
Lets say I have a group support#xyz.com which have members
member_1#xyz.com
member_2#xyz.com
and so on..
Same way there is another group help#xyz.com which have members
member_1#xyz.com
member_3#xyz.com
and so on..
When I get any mail for support#xyz.com it is forwarded to it's member and same way for help#xyz.com.
mail :from => the_person_who_sent_mail,
:to => members_email_id,
:subject => mail_subject,
:reply_to => the_group_name#xyz.com
And it appears like mail was sent to me.
But I want to do a change in this as shown below :
When it lands in my inbox it should be something like
From : the_person_who_sent_mail#something.com
Reply To : the_group_name#xyz.com
To : the_group_name#xyz.com
But according to my setting it comes like
From : the_person_who_sent_mail#something.com
Reply To : the_group_name#xyz.com
To : members_email_id#xyz.com
In my case it shows that the mail is destined to me. But in the first case it shows to whom the mail was originally destined for.
Mailing list servers accomplish this with BCC, like so:
mail :from => the_person_who_sent_mail,
:to => the_group_name#xyz.com,
:subject => mail_subject,
:reply_to => the_group_name#xyz.com,
:bcc => [members_email_id]
The downside to this is that your mailserver will actually attempt to send the e-mail to the_group_name#xyz.com, so it will have to know to ignore this message. However, when the message arrives in the user's inbox, the To: will be the_group_name#xyz.com.
I use FbGraph gem and this part of code:
page = FbGraph::Page.new(ID_OF_MY_PAGE)
feed = page.feed!(
:access_token => access_token,
:subject => 'testing',
:message => 'Hey, I\'m testing you!'
)
It's working only if I (as the owner of the page) am logged in. I would need to run this task with CRON. Is there any way to set up the tokens for posting statuses if I wouldn't need to be logged in?
The following code seems to work if there is one user, but truncate the email for multiple users:
users.each do |user|
mail(
:to => user.email,
:subject => 'Hi',
:template_name => 'notification'
).deliver
Is this the proper way to send a few emails?
Ruby on Rails 3.2.2
Heroku
SendGrid
I think this is what you're looking for:
def my_mailer_method
users = User.find({ ... })
headers['X-SMTPAPI'] = { :to => users.to_a }.to_json
mail(
:to => "this.will#be.ignored.com",
:subject => "Hi",
:template_name => "notification"
).deliver
end
This sends a message to any number of recipients use the SendGrid's SMTP API. You can find further information on the docs page.
You might also want to take a look at the sendgrid rails gem
To send email to multiple users: pass an array
Replace
:to => user.email
with
:to => users.map(&:email)
more > rails guide
If it is not important for you to hide email addresses from each other, you can specify recipients in a comma delimited string.
It seems that the problem is that each instance of the Mailer can only send one email. Perhaps the mail object is falling out of scope and getting cleaned up by the garbage collector...
The solution that worked was to iterate over the users outside of the Mailer, and call it once for each user. It may be slow but it should happen in the background anyway so it's fine.
I have function, which paying users:
def pay
require 'httpclient'
require 'xmlsimple'
clnt = HTTPClient.new
user = User.find(params[:user_id])
#params_id = params[:user_id]
credentials = {
'USER' => 'payer_1342623102_biz_api1.gmail.com',
'PWD' => '1342623141',
'SIGNATURE' => 'Ay2zwWYEoiRoHTTVv365EK8U1lNzAESedJw09MPnj0SEIENMKd6jvnKL '
}
header = {"X-PAYPAL-SECURITY-USERID" => "payer_1342623102_biz_api1.gmail.com",
"X-PAYPAL-SECURITY-PASSWORD" => "1342623141",
"X-PAYPAL-SECURITY-SIGNATURE" => "Ay2zwWYEoiRoHTTVv365EK8U1lNzAESedJw09MPnj0SEIENMKd6jvnKL ",
"X-PAYPAL-REQUEST-DATA-FORMAT" => "NV",
"X-PAYPAL-RESPONSE-DATA-FORMAT" => "XML",
"X-PAYPAL-APPLICATION-ID" => "APP-80W284485P519543T"
}
//here is data what is posting to PayPal
data = {"actionType" => "PAY",
"receiverList.receiver(0).email"=> user.email,
"receiverList.receiver(0).amount" => "10",
"currencyCode" => "USD",
"cancelUrl" => "http://127.0.0.1:3000/",
"returnUrl" => "http://127.0.0.1:3000/",
"requestEnvelope.errorLanguage" => "en_US"}
uri = "https://svcs.sandbox.paypal.com/AdaptivePayments/Pay"
res = clnt.post(uri, data, header)
end
From documentation:
Adaptive Payments API operation - use -
ipnNotificationUrl field of the Pay or Preapproval request
So, I should add into data variable:
"ipnNotificationUrl" => "myaapp.com"//my site url yes ?
I should put in this field my site url or not ?
How to get info from this notification ?
How to send some emails and do some action if transaction is successful ?
I can't test it locally, yes ?
How can I test it in sandbox ?
Yes, you should include the field if you want to receive notifications related to the payment,
You need to specify a URL that is reachable from the outside (As this is where PayPal will post the information to, from their servers).
This URL could be a PHP page, that upon receiving the IPN, and verifying it, sends out the emails you mentioned.
To simulate an IPN coming from PayPal, you can use the following tool from the sandbox developer page: https://developer.paypal.com/cgi-bin/devscr?cmd=_ipn-link-session
(Alternatively, you can complete a purchase in the sandbox, and if you specified the ipnNotificationURL in the API call, PayPal will send you one upon completion of the payment)