How to use mailto with material ui?
Asked Answered
H

4

10

Trying to find how to use mailto in material UI. I tried just using a simple tag within a ListItem, I tried using

<ListItem button component={Link} mailto='' />

I also tried

<ListItem button >
   <i class="material-icons mail_outline">mail_outline</i>
   <ListItemText primary="Support" />
  <a href="mailto:[email protected]"></a>
</ListItem>

I tried to find information about this on material-UI's website & Github but nothing. I would really appreciate some help.

Healion answered 16/2, 2018 at 0:15 Comment(0)
G
10

I based mine on @Gary Vernon Grubb's answer, and added it into a button.

<Button
   variant="contained"
   size="large"
   color="primary"
   target="_top"
   rel="noopener noreferrer"
   href={`mailto:[email protected]`}
>
   <Typography variant="button" style={{ fontSize: '0.69rem' }}>
      Send Documents
   </Typography>
</Button>
Gelhar answered 20/7, 2020 at 11:59 Comment(1)
How does one open the mailto in a new tab?Novick
C
8

If you set the component equal to a (the hyperlink tag), you can then use the href attribute to set the e-mail.

Thus, you'll get the following line.

<ListItem button key="Email" component="a" href="mailto:[email protected]">
Cadre answered 8/2, 2020 at 6:33 Comment(0)
P
3

Mailto is a Uniform Resource Identifier (URI) scheme for email addresses. It is used to produce hyperlinks on websites that allow users to send an email to a specific address without first having to copy it and enter it into an email client.

<ListItem>
   <a href="mailto:[email protected]" target="_top">Send Mail</a>
</ListItem>

Above code works well for me in ReactJs with Material-UI library included.

Paederast answered 16/2, 2018 at 5:16 Comment(1)
How does one open the mailto in a new tab?Novick
P
3

This is how I do it with material-ui:

    <FormControlLabel
        control={
            <a target="_top"
                rel="noopener noreferrer"
                href="mailto:[email protected]">
                <IconButton color="primary">
                    <EmailOutline /> {/* icon */}
                </IconButton>
            </a>
        }
        label={"[email protected]"}
        labelPlacement="end"
    />
Pyromagnetic answered 26/9, 2018 at 2:54 Comment(1)
How does one open the mailto in a new tab?Novick

© 2022 - 2024 — McMap. All rights reserved.