Last active
April 28, 2023 07:10
-
-
Save totuworld/4586fc3ee012a8aac3ea713c85894f45 to your computer and use it in GitHub Desktop.
appsScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<base target="_top"> | |
</head> | |
<body> | |
<img src='cid:megaphone' /> | |
<h2>안녕하세요 <?= name ?>님</h2> | |
<p> | |
이번달 청구금액 안내드립니다.<br /> | |
<br /> | |
청구금액: <?= billing ?> <br /> | |
정산 내역서는 첨부파일 참고 부탁드립니다.<br /> | |
감사합니다. | |
</p> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<base target="_top"> | |
<style type='text/css'> | |
@font-face { | |
font-family: 'BMDOHYEON'; | |
src: url('https://cdn.jsdelivr.net/gh/projectnoonnu/[email protected]/BMDOHYEON.woff') format('woff'); | |
font-weight: normal; | |
font-style: normal; | |
} | |
li { | |
font-family: 'BMDOHYEON' | |
} | |
</style> | |
</head> | |
<body> | |
<img src='cid:megaphone' style="width: 30%" /> | |
<h1>신규 입사자를 소개합니다</h1> | |
<? for (let d = 0; d < data.length; d++) { ?> | |
<? let members = data[d].members; ?> | |
<p><?= data[d].division ?></p> | |
<ul> | |
<? for (var i = 0; i < members.length; i++) { ?> | |
<li><a href="<?!= members[i].link ?>"><p><?= members[i].name ?><br /><?= members[i].team ?><br /><?= members[i].department ?></p><img src="<?!= members[i].img ?>" style="width: 90px;" /></a></li> | |
<? } ?> | |
</ul> | |
<? } ?> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sendEmailWithFile() { | |
const sheets = SpreadsheetApp.getActiveSpreadsheet(); | |
const list = sheets.getSheetByName('list'); | |
const template = sheets.getSheetByName('template'); | |
const subject = template.getRange(2, 1).getValue(); | |
const lastRow = list.getLastRow(); | |
const folderID = 'folder id'; // 폴더 id | |
const folder = DriveApp.getFolderById(folderID); | |
const files = folder.getFiles(); | |
const fileMap = {}; | |
while (files.hasNext()) { | |
let file = files.next(); | |
const fileName = file.getName().replace(/\s/g, '').normalize('NFC'); | |
const encodeFileName = Utilities.base64Encode(fileName); | |
fileMap[encodeFileName] = file; | |
} | |
let htmlTemplate = HtmlService.createTemplateFromFile('template'); | |
const imageFile = DriveApp.getFileById('file id'); | |
const inlineImages = { | |
megaphone: imageFile | |
} | |
for (let i = 2; i < lastRow + 1; i++) { | |
const email = list.getRange(i, 3).getValue(); // 이메일 주소 | |
const name = list.getRange(i, 1).getValue(); // 담당자 명 | |
const billing = list.getRange(i, 4).getValue(); // 정산 금액 | |
const excelFileName = list.getRange(i, 5).getValue().replace(/\s/g, ''); // 보내야하는 정산내역서 명 | |
const encodeExcelFileName = Utilities.base64Encode(excelFileName); | |
const excelFile = fileMap[encodeExcelFileName]; | |
const attachments = [excelFile]; | |
htmlTemplate.name = name; | |
htmlTemplate.billing = billing; | |
MailApp.sendEmail( | |
{ | |
to: email, | |
subject, | |
htmlBody: htmlTemplate.evaluate().getContent(), | |
attachments: attachments, | |
inlineImages: inlineImages, | |
} | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment