File size: 3,049 Bytes
c559b14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import gradio as gr
import pandas as pd
import smtplib, time, random
from email.mime.text import MIMEText

# -----------------------------
# 1) AI Email Generator
# -----------------------------
def generate_email(name, company, role, tone="professional"):
    email_templates = {
        "professional": f"""
        Subject: Exploring {role} opportunities at {company}
        
        Hi {name},
        I admire {company}'s work in your industry. Based on my skills and experience,
        I believe I can contribute meaningfully to your {role} team. 
        Would you be open to a quick chat?
        
        Best regards,
        [Your Name]
        """,
        "friendly": f"""
        Subject: Love what {company} is building 🚀
        
        Hey {name},
        Just wanted to say I really like what you’re doing at {company}.
        I’d love to explore if there’s a role for me to add value as {role}.
        
        Cheers,
        [Your Name]
        """
    }
    return email_templates.get(tone, email_templates["professional"])

# -----------------------------
# 2) Email Sender with Rotation
# -----------------------------
def send_email(sender_email, sender_password, receiver_email, email_body):
    msg = MIMEText(email_body, "plain")
    msg["From"] = sender_email
    msg["To"] = receiver_email
    msg["Subject"] = "Let's Connect"
    
    try:
        with smtplib.SMTP_SSL("smtp.gmail.com", 465) as server:
            server.login(sender_email, sender_password)
            server.sendmail(sender_email, receiver_email, msg.as_string())
        return "✅ Sent!"
    except Exception as e:
        return f"❌ Error: {e}"

# -----------------------------
# 3) Bulk Campaign Handler
# -----------------------------
def run_campaign(file, sender_email, sender_password, tone):
    leads = pd.read_csv(file.name)
    logs = []
    for _, row in leads.iterrows():
        name, company, role, email = row["Name"], row["Company"], row["Role"], row["Email"]
        email_text = generate_email(name, company, role, tone)
        status = send_email(sender_email, sender_password, email, email_text)
        logs.append([name, company, email, status])
        time.sleep(random.randint(10,30))  # delay to avoid spam flags
    log_df = pd.DataFrame(logs, columns=["Name","Company","Email","Status"])
    return log_df

# -----------------------------
# 4) Gradio App
# -----------------------------
with gr.Blocks() as app:
    gr.Markdown("## 📧 AI Cold Outreach Campaign Manager")
    
    with gr.Row():
        sender = gr.Textbox(label="Your Email")
        password = gr.Textbox(label="Your Email Password", type="password")
    
    file = gr.File(label="Upload Leads CSV (Name,Company,Role,Email)", file_types=[".csv"])
    tone = gr.Radio(["professional", "friendly"], label="Tone", value="professional")
    
    output = gr.Dataframe(label="Campaign Logs")
    
    run_btn = gr.Button("🚀 Run Campaign")
    
    run_btn.click(run_campaign, [file, sender, password, tone], output)

app.launch()