send.go

 1package icloud
 2
 3import (
 4	"fmt"
 5	"log"
 6	"net/smtp"
 7)
 8
 9func main(to_email []string, password string, subject string, body string, from_email string) {
10	// --- Configuration ---
11	// Your full iCloud email address.
12	
13
14	// Requires an app-specific password for your iCloud account.
15	// 
16	// How to generate an app-specific password:
17	// 1. Go to https://appleid.apple.com
18	// 2. Sign in with your Apple ID and password.
19	// 3. Under "Sign-In and Security", click on "App-Specific Passwords".
20	// 4. Click "Generate an app-specific password" or the "+" button.
21	// 5. Enter a name for the password (e.g., "Go Email Script") and click "Create".
22	// FIXME: 6. Copy the generated password and paste it in configs. 
23
24
25	// iCloud SMTP server settings.
26	smtpHost := "smtp.mail.me.com"
27	smtpPort := "587"
28
29	// --- Email Content ---
30	message := []byte(subject + body)
31
32	// --- Authentication ---
33	// Create an authentication object.
34	auth := smtp.PlainAuth("", from_email, password, smtpHost)
35
36	// --- Sending the Email ---
37	// Connect to the SMTP server, authenticate, and send the email.
38	err := smtp.SendMail(smtpHost+":"+smtpPort, auth, from_email, to_email, message)
39	if err != nil {
40		log.Fatalf("Failed to send email: %s", err)
41	}
42
43	fmt.Println("Email sent successfully!")
44}