Sendgrid template not set using setTemplateId - sendgrid

I'm not able to use template id for email body in email sent from sendgrid with following code (using 2.2):
val sendgrid = new SendGrid(sendgridapikey)
val sendgridEmail = new SG.Email()
sendgridEmail.setSubject("Invitation Email")
sendgridEmail.setFromName("Sender")
sendgridEmail.setTemplateId("6305c994-af9a-432e-9a07-5d7f493800e1")
sendgridEmail.setFrom("no-reply#domain.com")
sendgridEmail.addTo(to)
val response = sendgrid.send(sendgridEmail)
The email is sent if I remove setTemplateId line above but not with that.
Please help. thanks!

Related

Redirect SendGrid Webhook Events with an F5 using Custom Headers

When sending an email through SendGrid I am sending a custom header. Is there a way to configure the webhooks to get the custom header back from SendGrid so that a F5 iRule can be easily written to redirect the traffic based on the value in this custom header. I know I can use .addCustomArgs(...) to return custom data but I would like the custom data in the header.
var client = new SendGridClient("API_KEY");
var from = new EmailAddress("test#example.com", "Example User");
var subject = "Testing with SendGrid API";
var to = new EmailAddress("joe#test.com", "Example User");
var plainTextContent = "Test Content";
var htmlContent = "<strong>Testing with HTML content</strong>";
var msg = MailHelper.CreateSingleEmail(from, to, subject, plainTextContent, htmlContent);
var identifiers = new Dictionary<String, String>();
identifiers["application"] = "APP_NAME_GOES_HERE";
identifiers["resource"] = "RESOURCE_NAME_GOES_HERE";
msg.AddHeaders(identifiers);
var response = await client.SendEmailAsync(msg);
Twilio SendGrid developer evangelist here.
I'm afraid you cannot set headers for the SendGrid event webhook to send back. Custom arguments are sent as part of the JSON body.
I've not used F5 iRules before, but it seems that you may be able to parse and use the JSON body of a request within an iRule. According to this post, you can use iRules LX to deal with the JSON using JavaScript.
Or it seems that you can combine HTTP::collect with an HTTP_REQUEST_DATA block to collect and do things with the request body.

how i can reply to outlook email using python for the same sender by using below code?

I am trying to reply outlook email as we do manually it goes with previous conversations. But Below code is giving some error : Failed to send to the recipient address..I need to know how i can send it back to the person who sent me email..
import win32com.client, datetime
from datetime import timedelta
outlook =win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI") # to trigger outlook application
inbox = outlook.GetDefaultFolder(6) # 6 is used for the index of the folder
messages = inbox.Items
message = messages.GetLast()# message is treated as each mail in for loop
for message in messages:
if message.Subject=="request": # based on the subject replying to email
#body_content = message.body
message.Reply()
message.Body = "shortly will be processed!!!"
message.Send()
The reply is a MailItem returned by reply(). So try this:
reply = message.Reply()
reply.Body = "shortly will be processed!!!"
reply.Send()
continuing to above answer
to reply all:
`rplyall=message.ReplyAll()`
to reflect previous conversations:
`rplyall.Body="your message here"+rplyall.Body()`
`rplyall.Send()`
Since MailItem.Body is a String and it is not callable. Reference document
I think the correct code in #Akhil 's answer is
rplyall.Body = "your message here" + rplyall.Body
rplyall.Send()

Apache commons Email Alias Not working Properly in scala

I am using HtmlEmail Class of ApacheCommons for sending HTML formatted email with embedded images
Apache Commons Email API (v1.4) is used in my Scala project
I am not Seeing the Alias (MY REPORTS) as sender name in my Received Email
Following is my Function
#throws(classOf[EmailException])
#throws(classOf[Exception])
def createHTMLEmailMessage(htmlContent: String): EmailMessage = {
val email = new HtmlEmail
// alternative message if the client does not support html
email.setHtmlMsg(htmlContent)
email.addTo("TO_address#gmail.com")
email.setFrom("MY_address#GMAIL.com", "MY REPORTS")
email.setHostName("MY_HOSTNAME")
email.setSmtpPort(587)
email.setAuthentication("USERNAME","PASSWORD")
email.setStartTLSEnabled(true)
email.setSSLOnConnect(false)
email.setSubject("Subject")
val emailMsg = EmailMessage(email)
emailMsg
}

Setting up Email notification with private message on web2py

I set up a website using web2py and I'm looking for help to setup an email notification that will email the the person when they get a private message.
I already have the system able to have a semi message system/private message and I'm wondering how do I integrate that all together so that if a person gets a message, the system can automatically email that user. I been looking around to how to set it up but no luck for myself.
Thank you.
Edit: Before I start trying to integrate the messaging system, I wanted to test it out with the registration since that's the only thing I could find about web2py and email notification.
Edit2: Got the register to work and it says "email is sent". However, no actual email is sent.
This is all in the Models, menu.py. Also tried putting this in the controller, default.py.
auth.settings.register_next = URL('Welcome')
def Welcome():
User_Email = auth.user.email
mail.send(User_Email,'Welcome To website','Welcome To website')
if request.vars.lan == 'En':
redirect('index',vars={'lan':'En'})
else:
redirect('index')
#from gluon.tools import Mail
#mail = Mail()
#mail.settings. = True
#mail = auth.settings.mailer
mail = auth.settings.mailer
mail.settings.tls = False
mail.settings.server = "tls://smtp.gmail.com:587"
mail.settings.sender = "...#gmail.com"
mail.settings.login = "...#gmail.com:password"
# sends an verification e-mail upon registration
auth.settings.registration_requires_verification = True
def send_email(user, subject):
message = "" "Multi line string for %(first_name)s......"
message = open("somefile.html", "r").read()
# you also have the option to include everyone in bcc=[...]
mail.send(to=user.email,
subject=subject,
message=message % user)
user = db(db.auth_user).select()
for user in user:
send_email(user, "some subject")
Also have in the controller/default.py
def login():
auth.settings.registration_requires_verification = True
auth.settings.registration_requires_approval = False
auth.settings.reset_password_requires_verification = True

Play Framework [play-mailer]: how to ensure each receiver sees only his or her email address in the TO field

Here below is the code to send an email with play-mailer:
import play.api.libs.mailer._
...
val email = Email(
"My Subject",
"Me <j3d#domain.com>",
Seq("john#domain.com", "joe#domain.com", "jack#domain.com"),
bodyText = Some("Some text..."),
bodyHtml = Some("<p>Some text...</p>")
)
MailerPlugin.send(email)
The problem is that receivers see all the recipients the email was sent to. Of course, an option could be to invoke MailerPlugin.send for every single recipient... but I'm wondering if there is a better way to ensure each receiver sees only his or her email address in the to field.
Perhaps the best solution will be using hidden recepient which aka BCC. Emailer plugin has method addBcc(String address):
public void addBcc(String address) {
this.bcc.add(address);
}
Regards!