Lotus notes mail using java script from HTML - javascript

I am developing an application to send mail to a group of user using java script from Lotus notes. we are using shared mailbox for a user.
When i trigger this mail script it is sending from my personal mailbox
Is it possible to trigger the mail from the shared mailbox?
<script>
function sendEmail()
{
var notesDatabase;
var notesSessiona;
notesSessiona = new ActiveXObject("Notes.NotesSession");
notesDatabase = notesSessiona.GETDATABASE("staralliancesupport", "");
notesDatabase.OPENMAIL();
var mailItem = notesDatabase.CreateDocument();
mailItem.subject = te.value +" Outage"+" "+text11.value+tex111.value+tex11.value+tex21.value+tex31.value+tex41.value+tex51.value+tex61.value+tex71.value+tex81.value+tex91.value+" "+ text.value+" "+ tex.value+" session down"
mailItem.sendto = "nathan.sabari#tcs.com";
mailItem.copyto = textbox_1.value;
mailItem.BlindCopyTo = "";
mailItem.Body = "Dear All,\n\nNote: This e-mail is sent to Star Alliance member carrier contacts, their business partners and provider help desks.\n\nStar Alliance would like to inform you about the "+ tex.value +" interruption between Star Alliance and-"+" "+te.value+" "+text11.value+tex111.value+tex11.value+tex21.value+tex31.value+tex41.value+tex51.value+tex61.value+tex71.value+tex81.value+tex91.value+" "+ text.value+".\n\nWe are liaising with the airline's service desk to get more information regarding this issue.\n\n--\n\nStar Alliance Support\nEmail support at: Staralliance.support#tcs.com\nTelephone contact No: +1877 292 9784\n"
mailItem.Send (0);
}
</script>

Changing the database will not change the sender. The server always puts the current username in the sender name. You need to write your message directly to the mail.box file instead of using the NotesDocument.Send() method.
See Knut's answer to an earlier question about this. It contains a link to a script by Karl-Henry Martinsson that demonstrates the technique. It's LoutsScript, though, so you're going to have to translate that script to JavaScript.
For your specific problem, the most important lines of code in Karl-Henry's LotusScript code are:
Set mailbox = New NotesDatabase(mailservername,"mail.box")
If mailbox.Isopen = False Then
Print "mail.box on " & mailservername & " could not be opened"
Exit Sub
End If
Set me.maildoc = New NotesDocument(mailbox)
and...
If me.p_principal<>"" Then
Call maildoc.ReplaceItemValue("Principal", me.p_principal)
' If principal is set, we want to fix so mail looks like
' it is coming from that address, need to set these fields
Call maildoc.ReplaceItemValue("From", me.p_principal)
Call maildoc.ReplaceItemValue("Sender", me.p_principal)
Call maildoc.ReplaceItemValue("ReplyTo", me.p_principal)
Call maildoc.ReplaceItemValue("SMTPOriginator", me.p_principal)
End If
where me.p_principal contains the address he wants the message to come from, and...
Call maildoc.Save(True,False) ' Save in mail.box
Note that he doesn't call maildoc.Send() when he wants to control the From address. He just calls maildoc.Save(), and this works because he is saving it in the mail.box file.

Related

Inline keyboard callback_query setup in Google Apps Script Telegram bot

I've managed to figure out how to attach an inline button to message from my Telegram bot. I'm not sure how to make this button actually do something.
I have a simple invoice table in my Google Spreadsheet. I manually connected a Form to it, through which managers can request some financial transactions.
My perfect scenario: on every new form submit bot sends me a message with all the transaction's data. It already works perfectly (I'm using variables from form responses in combination with sendMessage and UrlFetchApp.fetch).
Now, I want to attach a functional button that will delete the particular message it's connected to and then send me a "Transaction completed" message.
My inline keyboard code excerpt:
'{"inline_keyboard":[[{"text":"Del","callback_data":"delete_message"}]]}'
I use most primitive webhook:
function setWebhook() {
var url = telegramUrl + "/setWebhook?url=" + webAppUrl;
var response = UrlFetchApp.fetch(url);
}
And I have a doPost function for just replying to /start command (if some manager got lost in space and time):
function doPost(e) {
var contents = JSON.parse(e.postData.contents);
var chat_id = contents.message.from.id;
var fname = contents.message.from.first_name;
var text = (""+fname +", this bot is for notification only, fill the form located on our website.");
sendMessage(chat_id,text)
}
I've Googled a lot, and tried some solutions, but it seems like my callback listening still isn't working.

Is there any way to mail merge with my own domain name instead Gmail

Here what I want to do is :
Send an email by mail merge by writing a script in App Script. (Success)
I have configured 2 domain email addresses in my Gmail along with my basic Gmail address.
I want to send an email via xyz#domainname.com instead of xyz#gmail.com, the Google Sheets owner.
here what I have done to send an email via Gmail
var first = 0;
var last = 1;
var email = 2;
var emailTemp = HtmlService.createTemplateFromFile("email");
var ws = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("NAJ");
var data = ws.getRange("A2:C" + ws.getLastRow()).getValues();
data.forEach(function(row){
emailTemp.fn = row[first];
emailTemp.ln = row[last];
var htmlMessage = emailTemp.evaluate().getContent();
GmailApp.sendEmail(row[email], "Important Test", "Your email does not support HTML.",
{name: "Email App", htmlBody: htmlMessage}
);
});
}
The only thing I need is to change the sending email address.
Any help would be highly appreciated. pardon my bad English
Explanation:
Your goal is to send emails from a specific email account regardless of the email account that is currently executing the script.
Approach 1:
One way to approach that is to use an installable trigger. As per the documentation:
Installable triggers always run under the account of the person who
created them. For example, if you create an installable open trigger,
it runs when your colleague opens the document (if your colleague has
edit access), but it runs as your account. This means that if you
create a trigger to send an email when a document is opened, the email
is always be sent from your account, not necessarily the account that
opened the document.
The idea here is to create an installable onEdit trigger from xyz#domainname.com so whenever the other emails edit a particular cell, the emails will be send.
The limitation of this approach is that we need to make sure that we trigger the code when we really want to and not every time a cell is edited. We can create a checkbox, and upon clicking on the checkbox (it does not matter which account did that) then the script will be executed and the emails will sent by the email account who created the installable trigger.
Approach 2:
Create email aliases. Here is the official documentation on how to do that and also this thread might be useful to create them programmatically. The restriction here is that to add an email alias, you must be a Google Workspace administrator.
Solutions:
Solution 1:
Create a checkbox in cell D1 of the sheet NAJ. The cell is up to you but you need to adjust the script accordingly.
Change the name of the function to add the event object. This will allow us to get edit info such as which cell is edited.
The new function will be:
function myInstallableOnEditFunction(e) {
const arng = e.range;
if(arng.getSheet().getName()=="NAJ" && arng.getA1Notation()=='D1' && arng.getValue()==true){
var first = 0;
var last = 1;
var email = 2;
var emailTemp = HtmlService.createTemplateFromFile("email");
var ws = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("NAJ");
var data = ws.getRange("A2:C" + ws.getLastRow()).getValues();
data.forEach(function(row){
emailTemp.fn = row[first];
emailTemp.ln = row[last];
var htmlMessage = emailTemp.evaluate().getContent();
GmailApp.sendEmail(row[email], "Important Test", "Your email does not support HTML.",
{name: "Email App", htmlBody: htmlMessage}
);
});
}
}
Finally, create an installable onEdit trigger function from the xyz#domainname.com account. You can do that either manually from the current project's trigger menu or programmatically.
After that, upon clicking on cell D1 by any account, the emails will be sent by xyz#domainname.com.
Solution 2:
After you have created email aliases (see Approach 2), you can use the getAliases() method, here is a sample script. I haven't tested on my own, but you can explore also this possibility.
// Log the aliases for this Gmail account and send an email as the first one.
var me = Session.getActiveUser().getEmail();
var aliases = GmailApp.getAliases();
Logger.log(aliases);
if (aliases.length > 0) {
GmailApp.sendEmail(me, 'From an alias', 'A message from an alias!', {'from': aliases[0]});
} else {
GmailApp.sendEmail(me, 'No aliases found', 'You have no aliases.');
}

The letter gets into the spam folder in google mail

When users register, some emails get into the spam folder.
I have two functions:
The first will make a configuration for nodemailer.
function sendingLetter() {
return nodemailer.createTransport({
service: config.transport.service,
secure: config.transport.ssl,
auth: {
user: config.transport.user,
pass: config.transport.password
}
});
}
The second is making a template for sending by mail with a link
function statusCheck(file, replacements) {
let html_file = fs.readFileSync(file, { encoding: 'utf-8' });
let template = handlebars.compile(html_file);
let htmlToSend = template(replacements);
return htmlToSend;
}
The function of sending letters to the user's mail
const smtpTransport = sendingLetter();
const confirm_email = path.join(__dirname, '../views/email_templates/users/confirm_email.html');
...
let rand_hash = Date.now();
let link = 'https://' + config.kHostName + '/api/users/verify/' + rand_hash;
let replacements = {
target_link: link,
};
let htmlToSend = statusCheck(confirm_email, replacements);
let mailOptions = {
from: config.transport.user,
to: user_email,
subject: Constants.users.messages.subjectConfimEmail,
html: htmlToSend,
};
smtpTransport.sendMail(mailOptions);
The template in which the link will be inserted to be sent to the user by mail
<p>
We're ready to activate your account. All we need to do is make sure this is your email address.
</p>
<a href="{{target_link}}"
<div class="butten">
Confirm Email
</div>
</a>
In some cases, Google sends my email to a spam folder. Why it happens? What are some tips to avoid this?
There is an algorithm within Google to categorize the messages according to your interest and have probably been categorized as undesirable.
The classification of messages sent from any website as spam is one of the most important things that a webmaster should pay attention to. I will discuss in this article what things a webmaster should pay attention to to ensure that messages sent by him Its website as spam (spam) ends up in a non-spam folder or spam folder.
How do service providers classify messages as spam?
The e-mail service providers use many methods and tools to filter the incoming e-mails of the system and accordingly decide whether or not the message should be classified as an annoying message.
Content-based filtering "Content Filters"
Filter based on the letterhead of the email "Email Header Filters"
Filter based on blacklists "Blacklist Filters"
Filter based on user decision "User Rule-based filters"
Methods of Solution
First: Filter based on Content Content Filters
Through which the content of the message and the method of writing it to find out whether the message is disturbing or not, by comparing the content to a database containing a set of words used in the spam and certainly every service provider has his own words in this area called " Spam Trigger Words, "and there are many lists of English words that can be found using the previous search term in the Google search engine.
Also, the service providers, through this mechanism, search the way in which the message was written, especially if the HTML code was used to write the message, then the service provider makes sure that the code written is a clean code.
The following are some tips that can be provided to avoid placing your message as spam based on the filtering mechanism based on the content:
Make sure that the title of the subject is not too long and not so short that it is just one word.
Make sure that the title or text of the message is not fully capitalized when writing in English.
Make sure that the message title does not contain Re: unless the message is actually in response to a message sent by the recipient.
Do not use a question mark in the message title.
You can use the $ $ sign in a sequential address or message content, for example, $$$.
When you write a message in HTML, do not use video, JavaScript or JavaScript in the message, and make sure that the HTML code is clean, standard and written correctly according to HTML standards.
Second: Liquidation Based on the letterhead "Email Header Filters":
Through this mechanism the server receives the message of the search for any false data can be found in the letterhead and accordingly classified as an annoying message or not.
Third: Liquidation based on blacklists "Blacklist Filters":
Blacklists are constantly updated databases that contain a list of IP addresses for servers that are based on or send spam messages.
Fourth: Liquidation based on the user's decision "User Rule-based filters":
Although this mechanism is not of great importance because it depends on the decision of the recipient of the message itself, but it must be mentioned, and in this mechanism the recipient of the message itself to indicate the message received as an annoying message and therefore in the following times to be written by the same address The message will go to the spam folder directly.
In the end I apologize for my relatively weak English.

Webhooks in Bitcoin Transactions - How to Apply Business Logics?

I want to start accepting Bitcoin on my website.
In order to do that, I wrote the following piece of code, but I truly struggle to understand how I can implement proper business logic after that the transaction is completed.
Here is the code:
<html>
<head>
<title>Pay with Bitcoin</title>
<script>
//Gets the URL of the Webpage and gets the price value of this transaction in USD.
//For simplicity Here the Value is passed in the URL.
//However in production you wanna use POST instead of GET.
const myUrl = window.location.href;
const url = new URL(myUrl);
const usdPrice = url.searchParams.get("price");
//This is the function where all the magin happens
const showQR = () => {
//URL of the api which will provide us with current BTC exchange rate
const apiUrl = "https://blockchain.info/ticker";
const hr = new XMLHttpRequest();
hr.open('GET', apiUrl, true);
hr.onreadystatechange = function(){
//Make sure the API sent a valid response
if(hr.readyState == 4){
let ticker = JSON.parse(hr.responseText);
//Get last BTC/USD exchange value from the API , then convert Price from USD to BTC
let BTCprice = ticker.USD.last;
let btcToPay = usdPrice / BTCprice;
//Make sure you have just 8 decimal points in your BTC price!!
btcToPay = btcToPay.toFixed(8);
//Use google API (or other...) to create the QR code. Pass on your btc public address and
//the amount (btc price) dynamically created. Message and label parameters can be dynamic too.
let qrurl = "https://chart.googleapis.com/chart?chs=250x250&cht=qr&chl=bitcoin:1BAnkZn1qW42uRTyG2sCRN9F5kgtfb5Bci?amount="+btcToPay+"%26label=CarRental%26message=BookingID123456";
//Populate the 'btc' DIV with QR code and other info...
document.getElementById('btc').innerHTML = "<img src=" +qrurl+"><br> <span class = 'greenMoney'>" + usdPrice + " usd / " + btcToPay + " BTC </span>";
}
}
hr.send();
};
</script>
</head>
<body onload = "showQR()">
<h1>Pay with BitCoin</h1>
<div id = "btc">
</div>
</body>
</html>
This code does the following:
Gets current USD/BTC exchange rate using the blockchain API.
takes the price in USD for the URL and converts it into BTC
generates a QR code using google API.
Embeds the price, label and message into the QR code
Renders the QR code in a DIV
I ve also set up a web hook service which will be listening to new transactions happening in the specified wallet address. Then a callback to my server is made, by mean of a POST request.
The problem is: the label and message parameters passed to the QR code will not be written in the blockchain.
They are just a handy reference for the customer to remind him what that specific transaction paid for.
As a result the callback to my server is practically useless.
In fact, the callback doesn't return any Booking Id or any other piece of information which could help me to understand who paid for what. Needless to say, in this scenario no business logic is possible: I can't update the order status on my DB, I can't send a confirmation email to the right customer.
How can I embed relevant information (e.g. Booking ID) into the BTC payment, ideally through the QR code?
If this is possible, how can I retrieve this information later on when my server receives the callback informing me that a new payment was made to my BTC wallet?
In short, you can't.
When accepting payments, you are supposed to give each invoice a new BTC address. This way, when you receive notification of an incoming transaction, you can check the receiving address to see which invoice is being paid, and compare the received amount against the expected amount.
Note
Technically, you could embed stuff like a order ID into an OP_RETURN. However, most wallets don't support transactions like that, and any users who want to pay you from an exchange account would be unable to comply.
#Raghav Sood thank you for your input which routed me to the right direction.
Using NodeJS/Express/MongoDB in the backend, I managed to implement a solution which I would like to share here.
Before starting, I wanna make a big disclaimer: this solution is not the only one, it is not the best one, it is not the fastest and probably it is not the most elegant.
Anyway, this solution has the advantage of not relying on packaged third parties solutions. This is in line with the spirit of the whole "no intermediation" philosophy of the bitcoin community. Most imortantly, your XPub always stay in your server and is NOT shared with any external service, which is probably the wisest approach.
Having said that, here is how one can show dynamic unique BTC addresses to customers:
First of all , I put in place a counter which keeps track of how many btc addresses were created for customers from a my HD wallet.
This is important to make sure than you never present the same address twice to customers, which is good for privacy of all parties and also for the sake of implementing business logic in your app.
In order to do this, I store a "counter value" into my DB. Everytime someone visits the BTC payment page, this value is retrived from mongo using a "dealCount" function and is assigned to a "serialPay" variable, which is equal to the value gotten from Mongo + 1. In the backend, the code would be something like this:
`function dealCount(){`
return new Promise(function(resolve, reject){
Deal.find({_id: "ID_OF_OBJ_WHERE_YOU_STORE_COUNTER"}, function(err, data){
if(err){
console.log(err);
}
resolve(data[0].serialDeal + 1);
})
})
};
The new value obtained (which later on will be saved again into Mongo in order to keep track of addresses created) is used to generate the new BTC public address for the customer at hand. If you keep reading you will see how.
To create new public addresses dynamically, one needs the xPub Key of his or her HD Wallet. If one is coding in NodeJS there are a couple of libraries (which can be imported into the server) that will enable this operation rather easily: bitcoinjs-lib and/or bitcore-lib. Personally I opted for Bitcore-lib, because there are less dependencies to deal with and I found the supporting material easier to digest.
Codewise, address generation goes as follows:
const bitcore = require('bitcore-lib');
app.post("/pay.html", urlencodedParser, function(req, res){
let serialPay = dealCount();
serialPay.then(function(serialPay){
const pub = new bitcore.HDPublicKey('INSERT_HERE_YOUR_XPUB_KEY');
let derivedHdPk = pub.derive('m/0/'+serialPay);
let derivedPk = derivedHdPk.publicKey;
let myDynAddress = new bitcore.Address(derivedPk);
res.render('pay', {myDynAddress: myDynAddress});
});
});
Then, using EJS as a templating engine, I could easily make the receiving bitcoin address dynamic in the front-end (/pay.ejs):
let myDynAddress = "<%=myDynAddress%>";
let qrurl = "https://chart.googleapis.com/chart?chs=250x250&cht=qr&chl=bitcoin:"+myDynAddress+"?amount="+btcToPay+"%26label=CarRental";
This will generate the QR Code Dynamically. In the original question, one can see how to render that into the webpage. In the meantime one should also put in place a function to store the updated "serialPay" counter back to the DB.
At this point one should only start monitoring incoming (non-confirmed) payments to the dynamic BTC address generated. A simple way to do it, is using the blockchain.info websocket API. When the payment arrives, things go forward as suggested by #Raghav Sood: one checks the incoming transaction making sure the customer paid the right amount to the right address.
Now you know who paid for what and all sorts of business logics can be triggered.

Send email in HTA using JavaScript and hide the sender's email address

I'm using an HTA at work with many options, now I'm trying to add a page that allows you to send an email directly from the HTA without opening MS Outlook.
I'm using Outlook 2003. I tried two ways to create the email sending page:
1. Using Outlook.Application ActiveX Object - It didn't work because its seems to work only with Outlook 2007, So meanwhile I left it out of the question.
2. Using simple HTML with 'mailto:' - It is working fine to send simple Emails, but I have a problem that I'm not able to solve.
In Outlook I can send emails from a 'fake' address called 'Service Mail' ( I just write it in the 'From' field ) so customers won't be able to reply to my emails. I want to do it also in my HTA page, but I think this option doesn't exist.
Is there any way doing it? Maybe by using an ActiveX Object for outlook 2003 and do it with that object?
Important: I can only use client side languages, because I don't have a server.
Thanks,
Rotem
I've made a HTA in VBScript that sends email. It connects directly to the mail server. You don't need Outlook (or any other email client) installed so it's pretty useful. Use something like this:
With CreateObject("CDO.Message")
.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.server.com"
.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Subject = "The subject line"
.To = "recipient#email.com"
.From = "sender#email.com"
.TextBody = "The body of the email"
' or .CreateHTMLbody "page.htm"
.AddAttachment "C:\path\to\file.txt"
.Send
End With
... you get the idea.
Edit: Just saw this request was specifically for javascript, but it's essentially the same:
var mailobj = Server.CreateObject("CDO.Message");
mailobj.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.server.com";
mailobj.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2;
mailobj.Subject = "The subject line";
mailobj.To = "recipient#email.com";
mailobj.From = "sender#email.com";
mailobj.TextBody = "The body of the email";
mailobj.Configuration.Fields.Update();
mailobj.Send();

Categories