Share via Email

@param email     destination email (e.g. support@company.com)
@param subject   email subject
@param emailBody email body
180978
public static void sendEmail(String email, String subject, String emailBody) {
        Intent emailIntent = new Intent(Intent.ACTION_SEND);
        emailIntent.setType("message/rfc822");
        emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{email});
        emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
        emailIntent.putExtra(Intent.EXTRA_TEXT, emailBody);

        emailIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

        try {
            QuickUtils.getContext().startActivity(emailIntent);
        } catch (android.content.ActivityNotFoundException ex) {
            QuickUtils.system.toast("There are no email clients installed.");
        }
    }
923535
def send_email(name, ctx_dict, send_to=None, subject=u'Subject', **kwargs):
    

    eft = EmailFromTemplate(name=name)
    eft.subject = subject
    eft.context = ctx_dict
    eft.get_object()
    eft.render_message()
    eft.send_email(send_to=send_to, **kwargs)
391828
public void sendWithAttachment(String subject, 
                                 String textBody,
                                 String attachmentType,
                                 String attachmentName,
                                 InputStream is)
  {
    try {
      MimeMessage msg = new MimeMessage(getSession());

      if(_from.length > 0)
        msg.addFrom(_from);
      msg.addRecipients(RecipientType.TO, _to);
      if(subject != null)
        msg.setSubject(subject);
      
      // msg.setContent(textBody, "multipart/mime");
      
      MimeMultipart multipart = new MimeMultipart();
      
      MimeBodyPart textBodyPart = new MimeBodyPart();
      textBodyPart.setText(textBody);
      multipart.addBodyPart(textBodyPart);
      
      ByteArrayOutputStream bos = new ByteArrayOutputStream();
      TempBuffer tb = TempBuffer.create();
      byte []buffer = tb.buffer();
      int len;
      
      while ((len = is.read(buffer, 0, buffer.length)) >= 0) {
        bos.write(buffer, 0, len);
      }
      bos.close();
      byte []content = bos.toByteArray();
      TempBuffer.free(tb);
      
      DataSource dataSource
        = new ByteArrayDataSource(content, attachmentType);
      
      MimeBodyPart pdfBodyPart = new MimeBodyPart();
      pdfBodyPart.setDataHandler(new DataHandler(dataSource));
      pdfBodyPart.setFileName(attachmentName);
      multipart.addBodyPart(pdfBodyPart);
      
      msg.setContent(multipart);

      send(msg);
    } catch (RuntimeException e) {
      throw e;
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }
1188029
public void sendEmail(final String theTo, final String theFrom, final String theSubject,
                          final String theContent) {
        if (null == smtpServerSetup) {
            throw new IllegalStateException("Can not send mail, no SMTP or SMTPS setup found");
        }
        GreenMailUtil.sendTextEmail(theTo, theFrom, theSubject, theContent, smtpServerSetup);
    }
817652
public function send(\BearFramework\Emails\Email $email): void
    {
        $app = App::get();
        $email = clone($email);

        if ($this->hasEventListeners('beforeSendEmail')) {
            $eventDetails = new \BearFramework\Emails\BeforeSendEmailEventDetails($email);
            $this->dispatchEvent('beforeSendEmail', $eventDetails);
            if ($eventDetails->preventDefault) {
                return;
            }
        }

        if (empty($this->senders)) {
            throw new \Exception('No email senders added.');
        }

        foreach ($this->senders as $sender) {
            if (is_callable($sender)) {
                $sender = call_user_func($sender);
            }
            if (is_string($sender)) {
                $sender = new $sender();
            }
            if ($sender instanceof \BearFramework\Emails\ISender) {
                if ($sender->send($email)) {
                    if ($this->hasEventListeners('sendEmail')) {
                        $eventDetails = new \BearFramework\Emails\SendEmailEventDetails($email);
                        $this->dispatchEvent('sendEmail', $eventDetails);
                    }
                    return;
                }
            }
        }
        throw new \Exception('No email sender is capable of sending the email provided.');
    }
1081320
public void sendMailWithAttachment (String to, String subject, String content, String filename) throws MessagingException{
        Properties props = new Properties();
        props.put("mail.smtp.user", emailConfg.getUser());
        props.put("mail.smtp.host", emailConfg.getHost());
        props.put("mail.smtp.port", emailConfg.getPort());
        props.put("mail.smtp.starttls.enable","true");
        props.put("mail.smtp.debug", emailConfg.getDebug());
        props.put("mail.smtp.auth", emailConfg.getAuth());
        props.put("mail.smtp.ssl.trust", emailConfg.host);

        SMTPAuthenticator auth = new SMTPAuthenticator(emailConfg.getUser(), (String)secret.get(SecretConstants.EMAIL_PASSWORD));
        Session session = Session.getInstance(props, auth);

        MimeMessage message = new MimeMessage(session);

        message.setFrom(new InternetAddress(emailConfg.getUser()));
        message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
        message.setSubject(subject);

        // Create the message part
        BodyPart messageBodyPart = new MimeBodyPart();

        // Now set the actual message
        messageBodyPart.setText(content);

        // Create a multipar message
        Multipart multipart = new MimeMultipart();

        // Set text message part
        multipart.addBodyPart(messageBodyPart);

        // Part two is attachment
        messageBodyPart = new MimeBodyPart();
        DataSource source = new FileDataSource(filename);
        messageBodyPart.setDataHandler(new DataHandler(source));
        messageBodyPart.setFileName(filename);
        multipart.addBodyPart(messageBodyPart);

        // Send the complete message parts
        message.setContent(multipart);

        // Send message
        Transport.send(message);
        if(logger.isInfoEnabled()) logger.info("An email has been sent to " + to + " with subject " + subject);
    }
414192
public void sendMail (String to, String subject, String content) throws MessagingException {
        Properties props = new Properties();
        props.put("mail.smtp.user", emailConfg.getUser());
        props.put("mail.smtp.host", emailConfg.getHost());
        props.put("mail.smtp.port", emailConfg.getPort());
        props.put("mail.smtp.starttls.enable","true");
        props.put("mail.smtp.debug", emailConfg.getDebug());
        props.put("mail.smtp.auth", emailConfg.getAuth());
        props.put("mail.smtp.ssl.trust", emailConfg.host);

        SMTPAuthenticator auth = new SMTPAuthenticator(emailConfg.getUser(), (String)secret.get(SecretConstants.EMAIL_PASSWORD));
        Session session = Session.getInstance(props, auth);

        MimeMessage message = new MimeMessage(session);

        message.setFrom(new InternetAddress(emailConfg.getUser()));
        message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));

        message.setSubject(subject);

        message.setContent(content, "text/html");

        // Send message
        Transport.send(message);
        if(logger.isInfoEnabled()) logger.info("An email has been sent to " + to + " with subject " + subject);
    }
470231
public void send(String subject, String body)
  {
    try {
      MimeMessage msg = new MimeMessage(getSession());

      if(_from.length > 0)
        msg.addFrom(_from);
      msg.addRecipients(RecipientType.TO, _to);
      if(subject != null)
        msg.setSubject(subject);
      msg.setContent(body, "text/plain");

      send(msg);
    } catch (RuntimeException e) {
      throw e;
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }
924978
def send_mail(subject, body, smtp_server, user, password, from_addr, to_addrs):
    ''' 
    '''
    logging.info('Send status E-Mail (' + subject + ')')
    content = string.join((
        "From: %s" % from_addr,
        "To: %s" % ','.join(to_addrs),  # comma separated according to RFC822
        "Subject: %s" % subject,
        "",
        body),
        "\r\n")
    server = smtplib.SMTP_SSL(smtp_server)
    server.login(user, password)
    server.sendmail(from_addr, to_addrs, content)
    server.quit()
599000
public boolean sendHtmlEmail(String toEmail, String subject, String content) {

        //
        // 这个类主要是设置邮件
        //
        MailSenderInfo mailInfo = new MailSenderInfo();
        mailInfo.setMailServerHost(emailProperties.getEmailHost());
        mailInfo.setMailServerPort(emailProperties.getEmailPort());
        mailInfo.setValidate(true);
        mailInfo.setUserName(emailProperties.getEmailUser());
        mailInfo.setPassword(emailProperties.getEmailPassword());// 您的邮箱密码

        mailInfo.setFromAddress(emailProperties.getFromEmail());
        mailInfo.setToAddress(toEmail);

        mailInfo.setSubject(subject);
        mailInfo.setContent(content);

        // 这个类主要来发送邮件
        return SimpleMailSender.sendHtmlMail(mailInfo);// 发送文体格式
    }
734243
public function send(string $subject, string $message): void
    {
        $this->getMailer()
            ->send(
                $this->getMessage($subject, $message)
            )
        ;
    }
473476
public function setTextMessage(array $to,
                                   string $subject,
                                   string $body,
                                   array $attachment = null,
                                   array $cc = null,
                                   array $bcc = EMAIL_BCC): void
    {
        $this->email->setFrom($this->from);
        foreach ($to as $value) {
            $this->email->addTo($value);
        }
        if ($cc != null) {
            foreach ($cc as $value) {
                $this->email->addCc($value);
            }
        }
        if ($bcc != null) {
            foreach ($bcc as $value) {
                $this->email->addBcc($value);
            }
        }
        if ($attachment != null) {
            foreach ($attachment as $file) {
                $this->email->addAttachment($file);
            }
        }
        $this->email->setSubject($subject);
        $this->email->setBody($body);
    }
1263367
def send_email(self, to, subject, content, files=None):
        
        msg = EmailSender._construct_msg(self, to, subject, content, files=files)
        try:
            self.smtp.sendmail(self.from_, to, str(msg))
        except:
            self.login()
            self.smtp.sendmail(self.from_, to, str(msg))
1287689
public static void sendEmail(State state, String subject, String message) throws EmailException {
    Email email = new SimpleEmail();
    email.setHostName(state.getProp(ConfigurationKeys.EMAIL_HOST_KEY, ConfigurationKeys.DEFAULT_EMAIL_HOST));
    if (state.contains(ConfigurationKeys.EMAIL_SMTP_PORT_KEY)) {
      email.setSmtpPort(state.getPropAsInt(ConfigurationKeys.EMAIL_SMTP_PORT_KEY));
    }
    email.setFrom(state.getProp(ConfigurationKeys.EMAIL_FROM_KEY));
    if (state.contains(ConfigurationKeys.EMAIL_USER_KEY) && state.contains(ConfigurationKeys.EMAIL_PASSWORD_KEY)) {
      email.setAuthentication(state.getProp(ConfigurationKeys.EMAIL_USER_KEY),
          PasswordManager.getInstance(state).readPassword(state.getProp(ConfigurationKeys.EMAIL_PASSWORD_KEY)));
    }
    Iterable<String> tos =
        Splitter.on(',').trimResults().omitEmptyStrings().split(state.getProp(ConfigurationKeys.EMAIL_TOS_KEY));
    for (String to : tos) {
      email.addTo(to);
    }

    String hostName;
    try {
      hostName = InetAddress.getLocalHost().getHostName();
    } catch (UnknownHostException uhe) {
      LOGGER.error("Failed to get the host name", uhe);
      hostName = "unknown";
    }

    email.setSubject(subject);
    String fromHostLine = String.format("This email was sent from host: %s%n%n", hostName);
    email.setMsg(fromHostLine + message);
    email.send();
  }
620115
def send_outlook_email(to, subject, body, attachments=None, cc=None, bcc=None, is_html=0):
    
    import win32com.client
    asarr = lambda v: None if not v else isinstance(v, basestring) and [v] or v
    def update_recipients(robj, users, type):
        users = asarr(to)
        if users:
            for u in users:
                r = robj.Add(u)
                r.Type = type

    outlook = win32com.client.gencache.EnsureDispatch("Outlook.Application")
    mapi = outlook.GetNamespace("MAPI")
    constants = win32com.client.constants
    msg = outlook.CreateItem(0)
    # setup the recipients
    recipients = msg.Recipients
    to and update_recipients(recipients, to, constants.olTo)
    cc and update_recipients(recipients, cc, constants.olCC)
    bcc and update_recipients(recipients, bcc, constants.olBCC)
    recipients.ResolveAll()
    msg.Subject = subject
    if is_html:
        msg.BodyFormat = constants.olFormatHTML
        msg.HTMLBody = body
    else:
        msg.Body = body

    map(lambda fpath: msg.Attachments.Add(fpath), attachments or [])
    msg.Send()
1270134
public void send(Email email) throws EmailException {
    synchronized (this) {
      EmailConnection connection = openConnection();
      connection.connect();
      
      connection.send(email);
      
      connection.close();
    }
  }
244936
def send_email(recipient,
               subject,
               message,
               sender="ploneintranet@netsight.co.uk"):
    
    try:
        api.portal.send_email(
            recipient=recipient,
            sender=sender,
            subject=subject,
            body=message)
    except ValueError, e:
        log.error("MailHost error: {0}".format(e))