• 01-11-2023, 17:56:34
    #1
    Kimlik doğrulama veya yönetimden onay bekliyor.
    kullanıcı html form name, phone, mail ve mesaj girecek. girilen mesaj benim mailime gelmesini yapamadım bi türlü.
    send message basınca mesajın gönderildiğine dair bildiri yazıyor js kodlarından dolayı. fakat maile gelen bir şey yok.
    kodlarda yorum olan kısmı açınca send message hiç bir tepki vermiyor. js kodunu bile engelliyor.

    forma girilen mesajı kendi mailime nasıl alabilirim?

    <section class="contact" id="contact">
    
            <h2 class="heading">Contact <span>Me!</span></h2>
    
            <form id="myForm" action="/users" method="post">
                <div class="input-box">
                    <input type="text" name="name" placeholder="Name & Surname" required>
                    <input type="email" name="email" placeholder="Email Address" required>
                    <input type="tel" name="phone" placeholder="Phone Number" required>
                </div>
    
                <textarea name="message" id="message" cols="30" rows="10" placeholder="Your Message" required></textarea>
                <input type="submit" name="send" value="Send Message" class="btn">
                <div id="notification" style="color: limegreen; font-size: 18px; margin-top: 5px;"></div>
            </form>
    
        </section>
    from flask import Flask, render_template, request, jsonify
    from flask_mail import Mail, Message
    
    app = Flask(__name__, template_folder='template')
    
    app.config['MAIL_SERVER'] = 'smtp.gmail.com'
    app.config['MAIL_PORT'] = 587
    app.config['MAIL_USE_TLS'] = False
    app.config['MAIL_USE_SSL'] = True
    app.config['MAIL_USERNAME'] = 'asker244897@gmail.com'  # benim mail adresim
    app.config['MAIL_PASSWORD'] = 'wovivtrwmfzedsef'   # mail adresimin uygulama şifresi, gmail şifresi değil
    
    mail = Mail(app)
    
    @app.route("/")
    def home():
        return render_template("index.html", hata="")
    
    @app.route("/users", methods=['GET', 'POST'])
    def index():
        if request.method == 'POST':
            name = request.form.get('name')
            phone = request.form.get('phone')
            email = request.form.get('email')
            message = request.form.get('message')
    
            # if not name or not phone or not email or not message:
            #     return render_template("index.html")
            # else:
            #     msg = Message('Bu bir deneme mesajıdır', sender=email, recipients=['asker244897@gmail.com'])
            #     msg.body = f"Name: {name}\nPhone: {phone}\nEmail: {email}\nMessage: {message}"
    
            #     mail.send(msg)
    
                # return render_template("index.html", name=name, phone=phone, email=email, message=message, success_message="Your message has sent!")
    
            return jsonify({"success": True})
    
        return render_template("index.html", hata="")
    
    if __name__ == "__main__":
        app.run(debug=True)
  • 01-11-2023, 18:18:15
    #2
    Mail göndermeye çalıştığınız fonksiyon kısmını try catch içerisine alarak ve öncesinde de formdan verilerin eksiksiz gelip gelmediğini kontrol edebilmek için print ile gelen datayı yazıp deneyin ne çıktı verecek, eğer js tarafında ajax kullanıyorsanız o zaman js kodlarını da ekleyin, gmail yapılandırmalarını kontrol edin 3. Parti uygulama ya da az güvenli uygulamalara izin ver gibi bir şey vardı yanlış hatırlamıyorsam onun açık olduğundan emin olun eğer form sorunsuz geliyorsa mail yapılandırmasıyla ilgili sorun vardır tls true yaparak deneyin
  • 01-11-2023, 18:22:42
    #3
    Gmail "Daha az güvenli uygulama erişimine izin ver" ayarını açın. Python kodunuzu aşağıdaki gibi güncelleyin.
    from flask import Flask, render_template, request, jsonify
    from flask_mail import Mail, Message
    
    app = Flask(__name__, template_folder='template')
    
    app.config['MAIL_SERVER'] = 'smtp.gmail.com'
    app.config['MAIL_PORT'] = 587
    app.config['MAIL_USE_TLS'] = True
    app.config['MAIL_USE_SSL'] = False
    app.config['MAIL_USERNAME'] = 'asker244897@gmail.com'
    app.config['MAIL_PASSWORD'] = 'wovivtrwmfzedsef'
    
    mail = Mail(app)
    
    @app.route("/")
    def home():
        return render_template("index.html", hata="")
    
    @app.route("/users", methods=['GET', 'POST'])
    def index():
        if request.method == 'POST':
            name = request.form.get('name')
            phone = request.form.get('phone')
            email = request.form.get('email')
            message = request.form.get('message')
    
            try:
                msg = Message('Mesaj', sender=app.config['MAIL_USERNAME'], recipients=['asker244897@gmail.com'])
                msg.body = f"Name: {name}\nPhone: {phone}\nEmail: {email}\nMessage: {message}"
                mail.send(msg)
                return jsonify({"success": True})
            except Exception as e:
                return jsonify({"error": str(e), "success": False})
    
        return render_template("index.html", hata="")
    
    if __name__ == "__main__":
        app.run(debug=True)
  • 01-11-2023, 19:37:43
    #4
    GVertigang adlı üyeden alıntı: mesajı görüntüle
    Gmail "Daha az güvenli uygulama erişimine izin ver" ayarını açın. Python kodunuzu aşağıdaki gibi güncelleyin.
    from flask import Flask, render_template, request, jsonify
    from flask_mail import Mail, Message
    
    app = Flask(__name__, template_folder='template')
    
    app.config['MAIL_SERVER'] = 'smtp.gmail.com'
    app.config['MAIL_PORT'] = 587
    app.config['MAIL_USE_TLS'] = True
    app.config['MAIL_USE_SSL'] = False
    app.config['MAIL_USERNAME'] = 'asker244897@gmail.com'
    app.config['MAIL_PASSWORD'] = 'wovivtrwmfzedsef'
    
    mail = Mail(app)
    
    @app.route("/")
    def home():
        return render_template("index.html", hata="")
    
    @app.route("/users", methods=['GET', 'POST'])
    def index():
        if request.method == 'POST':
            name = request.form.get('name')
            phone = request.form.get('phone')
            email = request.form.get('email')
            message = request.form.get('message')
    
            try:
                msg = Message('Mesaj', sender=app.config['MAIL_USERNAME'], recipients=['asker244897@gmail.com'])
                msg.body = f"Name: {name}\nPhone: {phone}\nEmail: {email}\nMessage: {message}"
                mail.send(msg)
                return jsonify({"success": True})
            except Exception as e:
                return jsonify({"error": str(e), "success": False})
    
        return render_template("index.html", hata="")
    
    if __name__ == "__main__":
        app.run(debug=True)
    teşekkürler mail geldi fakat name, phone, mail ve message hepsi none olarak geliyor.
    yukarda app.config['MAIL_USERNAME'] = 'asker244897@gmail.com' ile
    msg = Message('Mesaj', sender=app.config['MAIL_USERNAME'], recipients=['asker244897@gmail.com']) sender alıcı mail oldugundan mı? sender kısmını sender=('email') yaptım yine none geliyor.

    Name: None
    Phone: None
    Email: None
    Message: None
  • 01-11-2023, 19:45:52
    #5
    bangBurak adlı üyeden alıntı: mesajı görüntüle
    teşekkürler mail geldi fakat name, phone, mail ve message hepsi none olarak geliyor.
    yukarda app.config['MAIL_USERNAME'] = 'asker244897@gmail.com' ile
    msg = Message('Mesaj', sender=app.config['MAIL_USERNAME'], recipients=['asker244897@gmail.com']) sender alıcı mail oldugundan mı? sender kısmını sender=('email') yaptım yine none geliyor.

    Name: None
    Phone: None
    Email: None
    Message: None
    F12 basıp Network kısmına gelerek formu gönderin. İstekleri kontrol ederek, /users adresine yapılan POST isteğini kontrol edin. Doğru gönderilmeyen kısmı orada görürsünüz. JavaScript veya başka bir kodunuz varsa paylaşın.
  • 02-11-2023, 00:28:46
    #6
    from flask import Flask, render_template, request, jsonify
    from flask_mail import Mail, Message
    
    app = Flask(__name__, template_folder='template')
    
    app.config['MAIL_SERVER'] = 'smtp.gmail.com'
    app.config['MAIL_PORT'] = 465  # For SSL
    app.config['MAIL_USE_TLS'] = False
    app.config['MAIL_USE_SSL'] = True
    app.config['MAIL_USERNAME'] = 'asker244897@gmail.com'  # your Gmail address
    app.config['MAIL_PASSWORD'] = 'your-app-password'  # your Gmail App Password
    
    mail = Mail(app)
    
    @app.route("/")
    def home():
        return render_template("index.html", hata="")
    
    @app.route("/users", methods=['GET', 'POST'])
    def index():
        if request.method == 'POST':
            name = request.form.get('name')
            phone = request.form.get('phone')
            email = request.form.get('email')
            message = request.form.get('message')
    
            if not name or not phone or not email or not message:
                return render_template("index.html")
            else:
                msg = Message('Subject of the Email', sender=email, recipients=['asker244897@gmail.com'])
                msg.body = f"Name: {name}\nPhone: {phone}\nEmail: {email}\nMessage: {message}"
    
                mail.send(msg)
    
                return render_template("index.html", name=name, phone=phone, email=email, message=message, success_message="Your message has been sent!")
    
        return render_template("index.html", hata="")
    
    if __name__ == "__main__":
        app.run(debug=True)

    html: kodu
    <section class="contact" id="contact">
        <h2 class="heading">Contact <span>Me!</span></h2>
        <form id="myForm" action="/users" method="post">
            <div class="input-box">
                <input type="text" name="name" placeholder="Name & Surname" required>
                <input type="email" name="email" placeholder="Email Address" required>
                <input type="tel" name="phone" placeholder="Phone Number" required>
            </div>
            <textarea name="message" id="message" cols="30" rows="10" placeholder="Your Message" required></textarea>
            <input type="submit" name="send" value="Send Message" class="btn">
            <div id="notification" style="color: limegreen; font-size: 18px; margin-top: 5px;"></div>
        </form>
    </section>
  • 05-11-2023, 07:37:52
    #7
    mesajın gönderildiğine dair js kodu ekleyince form gönderim yapmıyor.

    <section class="contact" id="contact">
    
            <h2 class="heading">Contact <span>Me!</span></h2>
    
            <form action="/users" method="post" id="myForm">
    
                <div class="input-box">
                    <input type="text" placeholder="Full Name" name="name" required>
                    <input type="email" placeholder="Email Address" name="email" required>
                    <input type="number" placeholder="Mobile Number" name="phone">
                </div>
    
                <textarea name="message" id="" cols="30" rows="10" placeholder="Your Message Here!" required></textarea>
                <input type="submit" value="Send Message" class="btn" name="send">
    
            </form>
            <div id="message"></div>
        </section>
    from flask import Flask, render_template, request, jsonify
    from flask_mail import Mail, Message
    
    app = Flask(__name__)
    
    app.config['MAIL_SERVER'] = 'smtp.gmail.com'
    app.config['MAIL_PORT'] = 587
    app.config['MAIL_USE_TLS'] = True
    app.config['MAIL_USE_SSL'] = False
    app.config['MAIL_USERNAME'] = 'asker244897@gmail.com'
    app.config['MAIL_PASSWORD'] = 'wovivtrwmfzedsef'
    
    mail = Mail(app)
    
    @app.route("/")
    def home():
        return render_template("index.html", hata="")
    
    @app.route("/users", methods=['POST'])
    def index():
        if request.method == 'POST':
            name = request.form.get('name')
            phone = request.form.get('phone')
            email = request.form.get('email')
            message = request.form.get('message')
    
            # print(name, phone, email, message)  
    
            try:
                msg = Message('Mesaj', sender=app.config['MAIL_USERNAME'], recipients=['asker244897@gmail.com'])
                msg.body = f"Name: {name}\nPhone: {phone}\nEmail: {email}\nMessage: {message}"
                mail.send(msg)
                # return jsonify({"success": True})  
                
            except Exception as e:
                app.logger.error(f"An error occurred: {str(e)}")
                # return jsonify({"error": "An error occurred while processing your request.", "success": False})
    
        return render_template("index.html", hata="")
    
    if __name__ == "__main__":
        app.run(debug=True)

    ekleyince flaskı engelleyen js kodu

    document.addEventListener('DOMContentLoaded', function () {
        document.getElementById('myForm').addEventListener('submit', function (e) {
            e.preventDefault();
    
            fetch('/users', {
                method: 'POST',
                body: new FormData(this),
            })
            .then(response => response.json())
            .then(data => {
                const messageDiv = document.getElementById('message');
                if (data.success) {
                    messageDiv.textContent = "mesaj başarıyla gönderildi!";
                    setTimeout(function() {
                        messageDiv.textContent = '';
                    }, 3000);
                } else {
                    messageDiv.textContent = "mesaj gönderilirken hata oluştu.";
                }
            })
            .catch(error => console.error('Hata:', error));
        });
    });
    kullanıcı send message tıklayınca mesajın gönderildiğine dair 3sn bildirim yapıp kaybolan bir kod