0
votes

I am using this code to send emails (composing email content getting text from the sheet named ranges:

//compose issue emails to student and admin 
function composeIssueEmail() {

  //student's name, last name and email
  var email = ss.getRangeByName("CourseProgressEmail").getValue()
  var name = ss.getRangeByName("CourseProgressName").getValue()
  var lastName = ss.getRangeByName("CourseProgressStudentLastName").getValue()

  var subj = ss.getRangeByName("SetUpIssueTitle").getValue()
  var subject = subj.replace("*imya*", name)
  var bodyText = ss.getRangeByName("SetUpIssueBody").getValue()
  var body = bodyText.replace("*imya*", name)
  var link = getChecksheetURL()
  var text = body.replace("*link*", link)

  //send email to student
  var studentEmail = sendEmail(email, subject, text)

  var adminEmail = "[email protected]"
  var adminSubj = ss.getRangeByName("SetUpAdminIssueTitle").getValue()
  var adminSubject = adminSubj.replace("*imya*", name)
  var adminSubjectFinal = adminSubject.replace("*familia*", lastName)
  var adminText = ss.getRangeByName("SetUpAdminIssueBody").getValue()
  var adminTextReplace = adminText.replace("*imia*", name)
  var adminBody = adminTextReplace.replace("*familia*", lastName)
  var adminText = adminBody.replace("*link*", link)

  //send email to admin
  sendEmail(adminEmail, adminSubjectFinal, adminText)
}

//gets current checksheet URL
function getChecksheetURL() {

  var Url = ss.getUrl()
  var linkMiddle = "#gid="
  var sheetID = sheet.getSheetId()

  var shecksheetURL = Url + linkMiddle + sheetID

  return shecksheetURL
}

//sends emails
function sendEmail(email, subject, body) {

  GmailApp.sendEmail(email, subject, body)

}

Execution transcript: [19-06-12 16:39:43:396 EEST] Execution succeeded [2.399 seconds total runtime]

It sends stably to the gmail account that is the same as spreadsheet's one.

But to another gmail account it sends about every other time.

Details:

  • This code is executed (I log the line after this code)

  • The emails are visible in my outbound box but not arriving to any of the boxes of the recepient gmail.

  • Not in spam etc.

  • I don't get any messages, error or bounce notifications.

I tried MailApp instead - it's even worse and sometimes doesn't send even to my own email.

I tried to change things in settings config, but didn't find anything to work.

I set up a filter "never send to spam" and "always star it" - didn't work.

I deleted a link from it so it has no link - didn't work.

What can be a solution?

1
Include the rest of your code - it could be something other than your sendEmail() line causing this.ross
Are there any messages in the Execution Transcript? Where are you getting the value for email from; a spreadsheet or the like which may have an incorrect string?sinaraheneba
@Altigraph it says Execution succeeded and shows that email was sent. And I see in in Sent section of gmail. But it didn't reach the recipient inbox. Sometimes does, sometimes not.kiki
Please include the execution transcript in your post and show the rest of your code, especially explaining where email is coming from.sinaraheneba
@ross no other special algorithms simply composing an email and a subject (which works well) and then this line. Nothing else.kiki

1 Answers

2
votes

I handled this issue. The issue is about anti-spam filters not about the code.

I gained more trust to the email account by adding "Reply To" option within GmailApp.sendEmail method. It magically solved the problem so each email reaches target now.