Google Spreadsheet Email If - forms

First, I am a complete beginner and have no idea what I am doing.
I am wanting to take a form that is submitted in Google forms and email the data to certain individuals. I got an example code from http://www.labnol.org/internet/google-docs-email-form/20884.
I changed the email and I got this to work. However now I would like to add a simple if statement so that depending on the first question in the from Who would you like to contact? it will send the email to different email address per different answer. Note: there are more than two choices so I imagine I will need more than one else statement.
I think I need something like this, but I am not sure how to make it work.
if(e.parameter.source == "Info") sendto = "bob#yahoo.com" else sendto = "bob#email.com"
Thanks in advance

Add the if else block where "source" is the name of the form field:
var email = Session.getActiveUser().getEmail();
if(e.parameter.source == "Info")
email = "bob#yahoo.com"
else if (e.parameter.source == "Info2")
email = "bob2#email.com"
else
email = "bob2#email.com"

Related

how can I force Google App Script MailApp.sendEmail to use a new thread for each email in a loop?

I am doing a simple app, I have an spread sheet with a few columns, one is an email addres and the others are filled with the information I want to send in an email to that addres. The code is really simple, it is just a while loop with the execution of MailApp.sendEmail with the data in each row.
The issue that I am having is that when I execute the app all the emails end up in the same email threard. And this makes really difficult to follow the responses beacause each email is independet. I've been looking for a while on how to force MailApp.sendEmail to start a new thread, but I can't find how to do it in the documentation or in the web.
The issue is that you are using the exact same subject for these emails and therefore they end up in the same email thread.
For example:
This will put all the emails in the same thread:
function myFunction() {
for (let i=0; i<2; i++){
MailApp.sendEmail("example#gmail.com",
"Test", // subject is the same for every email
"This is an test email");
}
}
This will put the emails in different threads:
function myFunction() {
for (let i=0; i<2; i++){
MailApp.sendEmail("example#gmail.com",
"Test"+i, // subject is different for every email
"This is an test email");
}
}
Instead of using i which is not very well descriptive as a subject, you could send the datetime:
"Test"+new Date()
although this might not work if the emails are sent instantly and therefore the subject will be the same again, but it might work in your case.
Ideally, you would want something that is relevant to the email, for example relevant to the body of your email.

Is there a reliable way to determine a person's SMS address given their phone number and email address?

Since programatically sending a text with Meteor from the user's own cell phone number seems to be problematic (see this), I'm thinking the way to do this could be to send the SMS / texts as an email.
I often do this manually from work when I text my wife from an email client; the "rub" is that the format for the addresses to use differ based on carrier. e.g., when I SMS my wife via email, I use and address like the following:
0871632810#txt.att.net
That obviously works for someone using att.net as their carrier. For other carriers, other naming schemes are used (which can be found here and here.
So my idea is, if I know the user's phone number and their email address, I can cobble together the correct SMS address to use as the "from" in an email. e.g., given the following:
Phone == 0871632810
Email == guinevere#att.net
...I could have a function like (pseudocode):
string getSMSAsEmailAddr(phone, email) {
var emailAsSMS;
if (email.contains('att.net') {
emailAsSMS = 'txt.att.net';
}
else if (email.contains('comcast.net') {
emailAsSMS = 'comcastpcs.textmsg';
}
. . .
return phone + '#' + emailAsSMS;
}
The problem is, can a person's carrier/valid SMS address always be determined by their email address? I'm thinking no - for example, what if a person has comcast but their email address is gmail, or something else altogether?
Is it necessary, in order to reliably build the needed SMS address, to know the user's carrier (both sender and receiver) and leave the email address out of the equation?
UPDATE
There is at least one for-pay service for returning carriers for a phone number, such as this API. There is also one called "CallFire" but both of these cost moolah ($$). I prefer a free option (yes, I'm a cheapskate).
I'm thinking the way to do this is something like:
var phoneNum = $('#phoneNumber').val(); // returns something like '0871632810'
var carrier = getCarrierForPhoneNumber(phoneNum);// returns something like 'att' or 'comcast' or whatever
var textAddrSuffix = getTextAddrSuffixForCarrierName(carrier); // returns (if carrier is 'att', as an example) something like '#txt.att.net'
var textAddrViaEmail = phoneNum + textAddrSuffix; // returns something like '0871632810#txt.att.net'
textAddrViaEmail can now be used as either the "to" or "from" email address.
No, but there is a library with a rather large database of them over at https://github.com/typpo/textbelt.

titanium multiple recipients email dialog

im using titanium and need to send an email to multiple recipients. the official docs only show how to send to one individual email address.
can someone please give a more concrete example how the getToRecipients and setToRecipients methods are applied correctly so that an email is sent to multiple recipients?
https://developer.appcelerator.com/question/149943/emaildialog-gettorecipients-does-not-work
i need to pass an array (contacts) to the emailDialog.ToRecipients property:
["email#example.net","email2#example.net"]
the code below does not work with this error message (ive also tried it unsuccessfully without the "[]" in setToRecipients):
Basic functions[2807:70b]
["email#example.net","email2#example.net"]is not a valid email
address.
var emails = JSON.stringify(contacts);
var emailDialog = Ti.UI.createEmailDialog();
emailDialog.setToRecipients([emails]);
emailDialog.subject = "Hello from Titanium";
emailDialog.messageBody = '<b>Appcelerator Titanium Rocks!</b>';
emailDialog.open();
thx for any info on this!
Have you tried this?
emailDialog.setToRecipients(contacts);
The Appcelerator Documentation says that EmailDialog.toRecipients is an String [].
See u!
Why do you pass your contacts through JSON.stringify and then put it inside array with one element?
EmailDialog.setToRecipients method requires array of strings, and every single one string should be proper email address. To make it work change your code into:
var emailDialog = Ti.UI.createEmailDialog();
emailDialog.setToRecipients(contacts);
emailDialog.subject = "Hello from Titanium";
emailDialog.messageBody = "<b>Appcelerator Titanium Rocks!</b>";
emailDialog.open();
I'm assuming that contacts variable contains this array (based on your error message):
var contacts = ["email#example.net","email2#example.net"];

Get sender email address in Infopath

I have a form sent by email that travels through different persons like this.
Person A --> Person B --> Person C
I want the person A to be informed when the form is treated by person C. So Person A needs to be in copy of the email sent by person B.
Because person A isn't always the same one, I think the best way to put him/her in copy is to use the "from" field of the email received by person B and to put it in copy.
But how can I find this address with infopath and how can I place it into my email data connection ?
I had this same question today myself and could not find much in the way of answers.
So... I did some work myself and came up with a few solutions.
First I don't believe there is any way to get/set the "From" address using the InfoPath OM. This means you will have to use one of the following options:
No Code:
You will be limited to providing a field on the form where "Person A" can put their email address and use this in the CC. for subsequent stages. That's kind of the only way and while it an extra burden to the user it does have the benefit of providing flexibility.
Code:
Write your own code to send the mail using Outlook Interop or System.Net.Mail and then you will be setting all of the addresses manually anyway.
If you are using AD or something else then you could always get the email address of the current use using System.DirectoryServices.AccountManagement.
Based on an assumption which I cannot find any documentation to back up. That InfoPath uses the account associated with the default store to send email using EmailSubmitConnection. You should be able to use Outlook Interop to find the address that InfoPath will use.
Here is a code sample:
using Outlook = Microsoft.Office.Interop.Outlook;
public string GetDefaultSenderAddress()
{
// This actually opens outlook in the same way as InfoPath does to send the message.
// which can be slow.
string DefaultAddress = string.Empty;
Outlook.Application OutlookApplication = new Outlook.Application();
string DefaultStoreId = OutlookApplication.Session.DefaultStore.StoreID;
foreach (Outlook.Account Account in OutlookApplication.Session.Accounts)
{
if (Account.DeliveryStore.StoreID == DefaultStoreId)
{
DefaultAddress = Account.SmtpAddress;
}
}
// Note you probably won't want to quit if you are about to send the email.
// However I have noticed that this doesn't seem to close Outlook anyway.
OutlookApplication.Quit();
return DefaultAddress;
}
You may have to provide a few more checks in case of different account types etc. But I believe it will work. (I tested it for my scenario and it does).
Note: Of course this opens an outlook instance which you will have to close as well. And it can be slow. Unless outlook is already open in which case it will be very quick. Anyhow when sending from InfoPath Outlook will have to be opened so if you do this just before sending then there should be no noticeable difference.
I would advise using a combination of the no code/with code options so provide a return address which is automatically complete to save the user time. But can be corrected if the user wishes to have the email returned to a different address of if there is a mistake.
Hope that you find that useful.

Sending email to a SAP inbox and an ordinary email inbox

I needed a function to send an email to an ordinary email address and to send on too to an SAP Inbox. I found this function:
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = gd_doc_data
put_in_outbox = 'X'
commit_work = 'X'
TABLES
packing_list = it_packing_list
contents_txt = it_message
receivers = it_receivers
EXCEPTIONS
too_many_receivers = 1
document_not_sent = 2
document_type_not_exist = 3
operation_no_authorization = 4
parameter_error = 5
x_error = 6
enqueue_error = 7
OTHERS = 8.
The it_receivers it's filled like this:
FREE wa_it_receivers.
wa_it_receivers-receiver = sy-uname. "&----- Assign SAP User Id
wa_it_receivers-rec_type = 'B'. "&-- Send to SAP Inbox
wa_it_receivers-com_type = 'INT'.
wa_it_receivers-notif_del = 'X'.
wa_it_receivers-notif_ndel = 'X'.
APPEND wa_it_receivers TO it_receivers .
This only send's the email to the SAP inbox. I went to the domain of the rec_type field to see which letter is so it can send the email to an ordinary email account. I believe it is 'A' but, as it only says external address. Is that the one? Thank you.
I don't know why people keep on digging up that old function module. I'd always recommend using the Business Communication Services API - it's well documented and much easier to use. The docs also contain an example on how to send to an external mail address.
Here you have a nice example of how to do it wiki.sdn.sap.com