I want to add a custom header value to my Lettre SMTP request. What is the correct way to do this? I want something like this but the code below is not working
use lettre::{SmtpClient, Transport, email::{Email, Header}};
let email = Email::builder()
.to("recipient#example.com")
.from("sender#example.com")
.header(Header::new("X-Custom-Header", "custom header value"))
.subject("Example subject")
.text("Example email body")
.build()
.unwrap();
The error I get with the code above is that no ::new method exists, this was not meant to work more show what I want to be able to do
Related
Composing new message in telethon I'm trying to make something like 'User (link) in chat (link) posted something', but failed.
According to https://github.com/LonamiWebs/Telethon/wiki/Special-links, I've tried links like tg://user?id=123 and tg://openmessage?chat_id=123, but that gives links in text that are not working.
Here's the example:
#client.on(events.NewMessage)
async def handler(event):
sender = await event.get_sender()
sender_id = event.sender_id
sender_link = 'tg://user?id=' + str(sender_id)
payload = '[%s] (%s) said something' % (sender.first_name, sender_link)
I'm expecting a message with hyperlinked username, but getting [Alex] (tg://user?id=123), and that link leads to nowhere.
You need to remove the space between [...] and (...). You should have [%s](%s).
Twit is right, but there are several alternatives. You can manually insert a MessageEntityMention to the parser, or you can use HTML parse_mode and the format. Note that both of these are better, consider for example a user named hello](tg://user?id=321)[. This user would not get a link, so you should avoid markdown as it's not possible to escape this.
My JSON is:
body =
{
"session_id":"45470003-6b84-4a2b-bf35-e850d1e2df8b",
"message":"Thanks for calling service desk, may I know the store number you are calling from?",
"callstatus":"InProgress",
"intent":"",
"responseStatusCode":null,
"responseStatusMsg":null,
"context":"getstorenumber"
}
How to get message value using Node js? Please let me know after testing.
i tried body.message and body['message'] and also body[0]['message']. I am always getting "undefined"
#Chris comment, since the problem is sorted out, Adding the answer to all members for future ref.
From node.js result, body is taken as JSON string, using JSON.parse.body converted to json object.
body =
{
"session_id":"45470003-6b84-4a2b-bf35-e850d1e2df8b",
"message":"Thanks for calling service desk, may I know the store number you are calling from?",
"callstatus":"InProgress",
"intent":"",
"responseStatusCode":null,
"responseStatusMsg":null,
"context":"getstorenumber"
}
JSON.parse.body
console.log(body.message);
I have a facade I'm using to wrap up my nLog calls. I'm using nLog's event properties to add a custom "longMessage" field. Here is the code:
public void Fatal(string shortMessage, string longMessage, Exception exception = null)
{
Logger _logger = LogManager.GetCurrentClassLogger();
LogEventInfo theEvent = new LogEventInfo(LogLevel.Debug, "", "Pass my custom value");
theEvent.Message = shortMessage;
theEvent.Properties["LongMessage"] = longMessage;
theEvent.Exception = exception;
_logger.Fatal(theEvent);
}
When I write nLog events to a file or to the database target, the LongMessage field renders correctly. But when I write to email, I get an empty string where my long message should be. Any ideas why outputting properties would work in a database target but not work in an email target?
<target name="themail" xsi:type="Mail"
smtpServer="VALID.INTERNAL.IP"
from="sender#address.com"
to="recip#address.com"
subject="${event-properties:item=LongMessage}"
body="${all-event-properties:format=[key]=[value]:separator=,:includeCallerInformation=true}"
html="true"
encoding="UTF-8">
I get the email just fine. It comes in great. But the subject and body are just blank. I've added other things to the subject and body to make sure I'm getting something in the subject and body of the email, and that works too. Everything works except the event-properties lookup -- and that only doesn't work on the email target.
I think you need to escape the equal sign in format - that's what I finally figured out:
${all-event-properties:format=[key]\=[value]:separator=,:includeCallerInformation=true}"
I try to create a button which send a mail using the doc's URL to a mail-adress entered in an editBox:
if(Contr.isNewNote()){
Contr.save();
}
var thisdoc = Contr.getDocument(true);
var tempdoc = database.createDocument();
tempdoc.replaceItemValue("Form", "Memo");
tempdoc.replaceItemValue("SendTo", thisdoc.getItemValue("Destinatari"));
tempdoc.replaceItemValue("Subject", "My application");
var tempbody:NotesRichtextItem = tempdoc.createRichTextItem("Body");
tempbody.appendText("Click for open the doc. in client")
tempbody.addNewLine(2);
tempbody.appendDocLink(thisdoc);
tempbody.addNewLine(2);
thisdoc.save(true,true);
tempbody.appendText("click for navigating via web")
tempbody.addNewLine(2);
tempbody.appendText(facesContext.getExternalContext().getRequest().getRequestURL().toString() +
"?action=readDocument&documentId=" + thisdoc.getUniversalID());
tempdoc.send();
thisdoc.recycle();
tempbody.recycle();
tempdoc.recycle();
But at tempdoc.send(); I get Exception occurred calling method NotesDocument.send() null
What is weird, is the fact that for an application on the same server the code is working, I just copy the code and just modified the doc datasource and the SendTo field name. Am I missing something? Thanks for your time.
I forget the issue but there's been reports of this problem I think if a bad character gets into the sendTo.
There's a comment on the email bean XSnippet: http://openntf.org/XSnippets.nsf/snippet.xsp?id=emailbean-send-dominodocument-html-emails-cw-embedded-images-attachments-custom-headerfooter
that said:
The solution that seems to work is to use the method :
emailHeader.addValText(xxx,"UTF-8")
instead of
emailHeader.setHeaderVal(xxx)
I'm not exactly sure how that might translate to SSJS.. but the problem might be with special characters..
My Kentico server is unable to send e-mails, so I have to transform my e-mail using MacroResolver, but send it using some other way.
var clients = new List<Client>();
var macroResolver = MacroResolver.GetInstance();
macroResolver.AddDynamicParameter("clients", clients);
var emailMessage = new EmailMessage {
From = "someone#somewhere.com",
Recipients = "otherone#somewhere.com",
Subject = "Whatever"
};
var template = EmailTemplateProvider.GetEmailTemplate(templateName, siteName);
EmailSender.SendEmailWithTemplateText(siteName, emailMessage, template, macroResolver, true);
In other words, I would like to use Kentico just as a Template Engine. Is there anyway to achieve this?
What SendEmailWithTemplateText method basically does is it fills empty fields of message by its equivalent from a template and resolve macro values in it. If you are only after message body, then you can create the email message by:
emailMessage.Body = macroResolver.ResolveMacros(emailMessage.Body);
emailMessage.PlainTextBody = macroResolver.ResolveMacros(emailMessage.PlainTextBody);
For most scenarios it's also better to tell the resolver to encode resolved values. You can do it by: resolver.EncodeResolvedValues = true;
Also you are passing whole 'clients' collection to the resolver. You'll probably need to take it one by one and generate emails in a loop.