Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Email does not comply with addr-spec of RFC 2822 #183

Open
petrus9 opened this issue Apr 23, 2024 · 12 comments
Open

Email does not comply with addr-spec of RFC 2822 #183

petrus9 opened this issue Apr 23, 2024 · 12 comments

Comments

@petrus9
Copy link

petrus9 commented Apr 23, 2024

When adding the following Name Lastname [email protected] to the default "to" or "from" I get the following error.

Symfony \ Component \ Mime \ Exception \ RfcComplianceException
Email "Name lastname <[email protected]>" does not comply with addr-spec of RFC 2822. But as far as I am concerned it does comply.

Here is my markdown for the contact form
contact.md

@petrus9
Copy link
Author

petrus9 commented Apr 23, 2024

This is how it actually shows up in the error screen:

image

@rhukster
Copy link
Member

rhukster commented Apr 24, 2024

If this provided contact.md is using the same configuration file from you other issue, there was no value for {{ config.plugins.email.from }} nor {{ config.plugins.email.to }}. These were both empty. These need to be provided i a valid email format: https://github.com/getgrav/grav-plugin-email?tab=readme-ov-file#specifying-email-addresses

You said you use "Name lastname <[email protected])>" so I tested with:

process:
    email:
        subject: "[Site Contact Form] {{ form.value.name|e }}"
        from: "Name lastname <[email protected]>"
        to: "Name lastname <[email protected]>"
...

And it worked totally 100% fine. Even without the quotes its fine:

process:
    email:
        subject: "[Site Contact Form] {{ form.value.name|e }}"
        from: Name lastname <[email protected]>
        to: Name lastname <[email protected]>

FYI, you should always include a reply_to: so when you receive an email from the contact form, you can click 'reply' and it will go to the user who entered the form data on your site. Something like:

reply_to: {mail:"{{ form.value.email }}", name:"{{ form.value.name|e }}"}

is the best solution assuming your form has a field for email and for name.

@petrus9
Copy link
Author

petrus9 commented Apr 24, 2024

Thanks for the reply_to tip. I implemented it and it works!

Here is my new email.yaml

enabled: true
from: 'John Doe <[email protected]>'
to: 'Jane Doe <[email protected]>'
mailer:
  engine: sendgrid
  smtp:
    server: localhost
    port: 25
    encryption: none
    user: null
    password: null
  sendmail:
    bin: '/usr/sbin/sendmail -bs'
content_type: text/html
debug: false
cc: null
bcc: null
reply_to: null
body: null

Which throws the RFC error

Here is my contact.md which I know does not have any lines for "name:" not sure what I need to fix here so that emails are sent to 'Jane Doe [email protected]' and come from 'John Doe [email protected]'

title: Contact
heading: 'Say Hello.'
form:
    action: /home
    name: contact-form
    fields:
        -
            name: name
            label: Name
            placeholder: Name
            type: text
            validate:
                required: true
        -
            name: email
            label: Email
            placeholder: Email
            type: email
            validate:
                required: true
        -
            name: message
            label: Message
            placeholder: Message
            type: textarea
            rows: 6
            validate:
                required: true
        -
            name: g-recaptcha-response
            label: Captcha
            type: captcha
            recaptcha_not_validated: 'Captcha not valid!'
    buttons:
        -
            type: submit
            value: 'Send Message'
    process:
        -
            captcha: true
            buttons: null
        -
            type: submit
            value: 'Send Message'
            process: null
        -
            email:
                from:
                    mail: '{{ config.plugins.email.from }}'
                to:
                    mail: '{{ config.plugins.email.to }}'
                reply_to:
                    mail: '{{ form.value.email }}'
                    name: '{{ form.value.name|e }}'
                subject: '[Contact] Message from {{ form.value.name|e }}'
                body: '{% include ''forms/data.html.twig'' %}'
        -
            save:
                fileprefix: contact-
                dateformat: Ymd-His-u
                extension: txt
                body: '{% include ''forms/data.txt.twig'' %}'
        -
            display: thank-you

@rhukster
Copy link
Member

OH, change your email process: email: section to:

-
            email:
                from: '{{ config.plugins.email.from }}'
                to: '{{ config.plugins.email.to }}'
                reply_to:
                    mail: '{{ form.value.email }}'
                    name: '{{ form.value.name|e }}'
                subject: '[Contact] Message from {{ form.value.name|e }}'
                body: '{% include ''forms/data.html.twig'' %}'

You were setting the 'email' only part (mail:) with the combined email + name. Just set to: and from: and you should be fine.

@petrus9
Copy link
Author

petrus9 commented Apr 24, 2024

when I change the process: email: section to your recommendation. I get:

Symfony\Component\Mime\Exception\RfcComplianceException thrown with message "Email "Jane Doe <[email protected]>" does not comply with addr-spec of RFC 2822."

I am assuming I have to add some kind of name field, right?

I am following the the formating given in the email plugin interface:

Screenshot 2024-04-24 152424

@rhukster
Copy link
Member

rhukster commented Apr 24, 2024

So you have quotes around it? Try removing. Maybe they are not regular quotes.

@petrus9
Copy link
Author

petrus9 commented Apr 24, 2024

So you have quotes around it? Try removing. Maybe they are not regular quotes.

No quotes

@rhukster
Copy link
Member

I’m at a loss 🤷‍♂️

works for me when I try.

@petrus9
Copy link
Author

petrus9 commented Apr 24, 2024

The way it shows up on my screen is like this:

Screenshot 2024-04-24 153150

@rhukster
Copy link
Member

Ya that’s weird. The escaping isn’t right. But I don’t even know how you could do that from a yaml configuration.

@petrus9
Copy link
Author

petrus9 commented Apr 24, 2024

The only way I get it to work is if my email.yaml looks like this:

enabled: true
from: '[email protected]'
to: '[email protected]'
mailer:
  engine: sendgrid
  smtp:
    server: localhost
    port: 25
    encryption: none
    user: null
    password: null
  sendmail:
    bin: '/usr/sbin/sendmail -bs'
content_type: text/html
debug: false
cc: null
bcc: null
reply_to: null
body: null

@petrus9
Copy link
Author

petrus9 commented Apr 24, 2024

@rhukster so from what you wrote above, it sounds like when you add name and email address to the Email plugin fields like so:

Screenshot 2024-04-24 162040

Using:

email:
                from: '{{ config.plugins.email.from }}'
                to: '{{ config.plugins.email.to }}'
                reply_to:
                    mail: '{{ form.value.email }}'
                    name: '{{ form.value.name|e }}'
                subject: '[Contact] Message from {{ form.value.name|e }}'
                body: '{% include ''forms/data.html.twig'' %}'        

Your email is delivered coming from John Doe <[email protected]> and is sent to Jane Doe ,<[email protected]> in full

in full name-addr format? is that what you mean by that you can't replicate this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants