| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250 |
- import express from 'express';
- import nodemailer from 'nodemailer';
- import cors from 'cors';
- const app = express();
- const PORT = process.env.PORT || 3001;
- // Middleware
- app.use(cors());
- app.use(express.json());
- // SMTP Configuration
- const smtpConfig = {
- host: 'smtp-relay.brevo.com',
- port: 587,
- secure: false, // TLS
- auth: {
- user: '9e8314001@smtp-brevo.com',
- pass: 'xsmtpsib-d4a7d55a9c3d79a2b4d8f5c17b0ac5e47530f0615e7e9945e9fdf97b90487c32-LXW7Hihe7Qb5J2tM'
- }
- };
- // Create transporter
- const transporter = nodemailer.createTransport(smtpConfig);
- // Welcome email template
- const createWelcomeEmail = (customerEmail) => {
- return {
- from: '"CCDW" <bob.yuxinyang@gmail.com>',
- to: customerEmail,
- subject: '👋 欢迎来到 CCDW!我们很高兴认识您',
- html: `
- <!DOCTYPE html>
- <html lang="zh-CN">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>欢迎来到 CCDW</title>
- </head>
- <body style="margin: 0; padding: 0; font-family: 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif; background-color: #0A192F;">
- <table role="presentation" style="width: 100%; border-collapse: collapse;">
- <tr>
- <td align="center" style="padding: 40px 20px;">
- <table role="presentation" style="max-width: 600px; width: 100%; border-collapse: collapse; background-color: #112240; border-radius: 16px; overflow: hidden; box-shadow: 0 4px 24px rgba(0,0,0,0.3);">
-
- <!-- Header -->
- <tr>
- <td style="padding: 40px 40px 20px; text-align: center; background: linear-gradient(135deg, #112240 0%, #0A192F 100%);">
- <h1 style="margin: 0; color: #64FFDA; font-size: 28px; font-weight: bold;">
- ✨ CCDW
- </h1>
- <p style="margin: 10px 0 0; color: #8892b0; font-size: 14px;">
- AI智能解决方案
- </p>
- </td>
- </tr>
-
- <!-- Main Content -->
- <tr>
- <td style="padding: 30px 40px;">
- <h2 style="margin: 0 0 20px; color: #e6f1ff; font-size: 22px; font-weight: 600;">
- 您好!欢迎认识我们 👋
- </h2>
-
- <p style="margin: 0 0 20px; color: #a8b2d1; font-size: 16px; line-height: 1.8;">
- 非常高兴收到您的来信!感谢您对 CCDW 的关注。
- </p>
-
- <p style="margin: 0 0 20px; color: #a8b2d1; font-size: 16px; line-height: 1.8;">
- 我们是一家专注于 AI 智能化解决方案的公司,致力于帮助企业和个人提升工作效率,释放创造力。
- </p>
-
- <div style="background-color: #0A192F; border-left: 4px solid #64FFDA; padding: 20px; margin: 25px 0; border-radius: 0 8px 8px 0;">
- <p style="margin: 0; color: #64FFDA; font-size: 16px; font-weight: 600;">
- 🤔 请问您想了解什么呢?
- </p>
- <p style="margin: 10px 0 0; color: #8892b0; font-size: 14px; line-height: 1.6;">
- 无论是 AI 咨询、智能化转型、还是定制化开发需求,我们都很乐意与您交流探讨!
- </p>
- </div>
-
- <p style="margin: 0 0 20px; color: #a8b2d1; font-size: 16px; line-height: 1.8;">
- 您可以直接回复此邮件,或通过以下方式联系我们:
- </p>
- </td>
- </tr>
-
- <!-- Contact Info -->
- <tr>
- <td style="padding: 0 40px 30px;">
- <table role="presentation" style="width: 100%; border-collapse: collapse; background-color: #0A192F; border-radius: 12px; overflow: hidden;">
- <tr>
- <td style="padding: 25px;">
- <h3 style="margin: 0 0 15px; color: #64FFDA; font-size: 16px; font-weight: 600;">
- 📞 联系方式
- </h3>
- <table role="presentation" style="border-collapse: collapse;">
- <tr>
- <td style="padding: 8px 0; color: #8892b0; font-size: 14px; width: 80px;">邮箱:</td>
- <td style="padding: 8px 0;">
- <a href="mailto:bob@ccdw.xyz" style="color: #64FFDA; text-decoration: none; font-size: 14px;">bob@ccdw.xyz</a>
- </td>
- </tr>
- <tr>
- <td style="padding: 8px 0; color: #8892b0; font-size: 14px;">电话:</td>
- <td style="padding: 8px 0;">
- <a href="tel:+8618602109196" style="color: #64FFDA; text-decoration: none; font-size: 14px;">186 0210 9196</a>
- </td>
- </tr>
- <tr>
- <td style="padding: 8px 0; color: #8892b0; font-size: 14px;">联系人:</td>
- <td style="padding: 8px 0; color: #e6f1ff; font-size: 14px;">Bob</td>
- </tr>
- </table>
- </td>
- </tr>
- </table>
- </td>
- </tr>
-
- <!-- Closing -->
- <tr>
- <td style="padding: 0 40px 40px;">
- <p style="margin: 0 0 15px; color: #a8b2d1; font-size: 16px; line-height: 1.8;">
- 期待与您的交流! 🚀
- </p>
- <p style="margin: 0; color: #e6f1ff; font-size: 16px;">
- <strong>Bob</strong><br>
- <span style="color: #8892b0; font-size: 14px;">CCDW 团队</span>
- </p>
- </td>
- </tr>
-
- <!-- Footer -->
- <tr>
- <td style="padding: 20px 40px; background-color: #0A192F; border-top: 1px solid #233554; text-align: center;">
- <p style="margin: 0; color: #495670; font-size: 12px;">
- © 2026 CCDW - 释放AI的力量,创造无限可能
- </p>
- </td>
- </tr>
-
- </table>
- </td>
- </tr>
- </table>
- </body>
- </html>
- `,
- text: `
- 您好!欢迎认识我们 👋
- 非常高兴收到您的来信!感谢您对 CCDW 的关注。
- 我们是一家专注于 AI 智能化解决方案的公司,致力于帮助企业和个人提升工作效率,释放创造力。
- 🤔 请问您想了解什么呢?
- 无论是 AI 咨询、智能化转型、还是定制化开发需求,我们都很乐意与您交流探讨!
- 您可以直接回复此邮件,或通过以下方式联系我们:
- 📞 联系方式
- 邮箱:bob@ccdw.xyz
- 电话:186 0210 9196
- 联系人:Bob
- 期待与您的交流! 🚀
- Bob
- CCDW 团队
- © 2026 CCDW - 释放AI的力量,创造无限可能
- `
- };
- };
- // Send welcome email endpoint
- app.post('/api/send-welcome-email', async (req, res) => {
- try {
- const { email } = req.body;
- if (!email) {
- return res.status(400).json({
- success: false,
- message: '请提供邮箱地址'
- });
- }
- // Validate email format
- const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
- if (!emailRegex.test(email)) {
- return res.status(400).json({
- success: false,
- message: '邮箱格式不正确'
- });
- }
- const mailOptions = createWelcomeEmail(email);
- await transporter.sendMail(mailOptions);
- console.log(`✅ Welcome email sent to: ${email}`);
- res.json({
- success: true,
- message: '欢迎邮件已发送!请查收您的邮箱。'
- });
- } catch (error) {
- console.error('❌ Email sending failed:', error);
- res.status(500).json({
- success: false,
- message: '邮件发送失败,请稍后重试。',
- error: error.message
- });
- }
- });
- // Health check
- app.get('/api/health', (req, res) => {
- res.json({ status: 'ok', timestamp: new Date().toISOString() });
- });
- // Serve static files in production
- // 假设部署结构:
- // /root
- // /dist (前端构建产物)
- // /server (后端代码)
- import path from 'path';
- import { fileURLToPath } from 'url';
- const __filename = fileURLToPath(import.meta.url);
- const __dirname = path.dirname(__filename);
- // 任何非 /api 开头的请求,都尝试服务静态文件
- // 注意:这应该放在 API 路由定义之后
- app.use(express.static(path.join(__dirname, '../dist')));
- // SPA Fallback: 所有未匹配的 GET 请求都返回 index.html
- app.get('*', (req, res) => {
- if (req.path.startsWith('/api')) {
- return res.status(404).json({ success: false, message: 'API endpoint not found' });
- }
- res.sendFile(path.join(__dirname, '../dist/index.html'));
- });
- // Start server
- app.listen(PORT, '0.0.0.0', () => {
- console.log(`🚀 Email server running on port ${PORT}`);
- });
|