配置邮箱

@param mailHost 邮件服务器
@param personal 个人名称
@param from 发件箱
@param key 密码
180959
public static void config(MailHost mailHost, String personal, String from, String key) {
        setHost(mailHost);
        setPersonal(personal);
        setFrom(from);
        setKey(key);
    }
396755
public static function sendSpammedMail($id, $key, $tranport = null)
    {
        $row = Kwf_Model_Abstract::getInstance('Kwf_Model_Mail')->getRow($id);
        if (!$row) return false;

        if (Kwf_Util_Check_Spam::getSpamKey($row) != $key) {
            return false;
        }

        if (!$row->mail_sent) {
            $row->is_spam = 0;
            $row->sendMail($tranport); // setzt mail_sent auf 1 und speichert
            return true;
        }
        return false;
    }
1030876
public static Session getSession(String host, final String username,
                                     final String password) {
        // 设置配置文件，邮件主机和是否认证
        Properties property = new Properties();
        property.put("mail.host", host);
        property.put("mail.smtp.auth", "true");
        // 设置用户名和密码
        Authenticator auth = new Authenticator() {
            @Override
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(username, password);
            }
        };
        // 获取与邮件主机的连接
        Session session = Session.getInstance(property, auth);
        return session;
    }
1126498
public MailRequest newTextMailRequest(String subject, String body) {
        return createMailRequest(generateRequestId(), false, subject, body);
    }
486525
public void addTo(String address, String personal) throws AddressException {
		if(to == null) {
			to = new ArrayList<>();
		}
		to.add( toInternetAddress(address, personal) );
	}
552489
public static void config(String host, String personal, String from, String key) {
        setHost(host);
        setPersonal(personal);
        setFrom(from);
        setKey(key);
    }
1014915
public Future<Boolean> sendEmail(EmailBody body, String to, String title, FilePart[] fileParts,
                                     JMailCallback callback) {
        if (StringUtils.isEmpty(to) || (body == null && fileParts == null)) {
            logger.debug("邮件没有设置接收人或者没有正文");
            execCallback(false, body, to, title, fileParts, null, this, callback);
            return ERROR;
        }

        EmailTask task = new EmailTask(body, to, title, fileParts, callback);
        return executor.submit(task);
    }
1211351
function Connection (type, sender, from) {
	
	// provide default 'from' values
	from = from || {};
	
	// connection-specific UUID
	this.connID = UTIL.createUUID();
	
	// a project-specific / supplied name (can be account or app name)
	this.name = '';

	// sender function associated with this connection
	this.connector = sender;
	
	// store pointers on how to respond
	this.type = type;
	
	// where the connection comes from (default to nothing)
	this.host = from.host || '';
	this.port = from.port || 0;

	// time when this connection is established
	this.time =	new Date();
	
	// append cookie, if available (this is useful if the event will be relayed to another server to execute,
	// cookie can then be preserved
	if (from.cookie)
		this.cookie = from.cookie;
}
188340
public com.authy.api.User createUser(String email, String phone, String countryCode) {
		User user = new User(email, phone, countryCode);
		
		String content = this.post(NEW_USER_PATH, user);

		return userFromXml(this.getStatus(), content);
	}
853937
public function sendEmail($emailFrom, $fromName, $emailTo, $toName = '', $replyTo = null, $subject, $message_html, $message_text = null, $transportConfig = null) {

	    $html = new MimePart($message_html);
	    $html->type = 'text/html';

	    $body = new MimeMessage();
	    
	    if ($message_text!=null){
	        
	        // Add Alternative Email Text Content
    	    $text = new MimePart($message_text);
    	    $text->type = 'text/plain';
    	    
    	    $body->addPart($html,$text);
    	    
	    }else{
	        $body->addPart($html);
	    }
	    
	    $message = new Message();
	    $message->setFrom($emailFrom, $fromName);
	    $message->addTo($emailTo);
	    $message->setSubject($subject);
	    $message->setEncoding('UTF-8');
	    $message->setSender($emailTo, $toName);
	    $message->setBody($body);
	    if ($replyTo!=null){
	        $message->addReplyTo($replyTo);
	    }

        $transport = new Sendmail();

        if(is_array($transportConfig) && $transportConfig) {
            /**
             * Program executes these lines when user passes
             * custom Transport Configuration Options ($transportConfig)
             * to specify their own Mailing Service Provider
             */
            try{
                // Setup SMTP transport using LOGIN authentication
                $transport = new SmtpTransport();
                $options   = new SmtpOptions(array(
                    'name'              => $transportConfig['name'],
                    'host'              => $transportConfig['host'],
                    'connection_class'  => $transportConfig['connectionClass'],
                    'connection_config' => array(
                        'username' => $transportConfig['username'],
                        'password' => $transportConfig['password'],
                        'ssl' => $transportConfig['ssl'],
                    ),
                    'port' => $transportConfig['port'],
                ));
                $transport->setOptions($options);
            }
            catch (\Exception $exception){
                throw new \Exception($exception->getMessage());
            }
        }

        $transport->send($message);
	}
186440
function EmailNode(n) {
        RED.nodes.createNode(this, n);
        this.topic = n.topic;
        this.name = n.name;
        this.outserver = n.server;
        this.outport = n.port;
        this.secure = n.secure;
        let flag = false;
        if (this.credentials && this.credentials.hasOwnProperty('userid')) {
            this.userid = this.credentials.userid;
        } else {
            if (globalkeys) {
                this.userid = globalkeys.user;
                flag = true;
            }
        }
        if (this.credentials && this.credentials.hasOwnProperty('password')) {
            this.password = this.credentials.password;
        } else {
            if (globalkeys) {
                this.password = globalkeys.pass;
                flag = true;
            }
        }
        if (flag) {
            RED.nodes.addCredentials(n.id, {userid: this.userid, password: this.password, global: true});
        }
        let node = this;

        let smtpOptions = {
            host: node.outserver,
            port: node.outport,
            secure: node.secure,
        };

        if (this.userid && this.password) {
            smtpOptions.auth = {
                user: node.userid,
                pass: node.password,
            };
        }
        let smtpTransport = nodemailer.createTransport(smtpOptions);

        this.on('input', function(msg) {
            let params = processValuesFromContext(node, msg, [
                {name: 'port', type: 'portType'},
                {name: 'server', type: 'serverType'},
                {name: 'userid', type: 'useridType'},
                {name: 'password', type: 'passwordType'},
            ]);
            console.log('params are ....');
            console.log(JSON.stringify(params));

            if (params.userid && params.password) {
                smtpOptions.auth = {
                    user: params.userid,
                    pass: params.password,
                };
            }

            if (params.port && params.server) {
                smtpOptions.host = params.server;
                smtpOptions.port = params.port;
            }


            if (msg.hasOwnProperty('payload')) {
                if (smtpTransport) {
                    node.status({fill: 'blue', shape: 'dot', text: 'email.status.sending'});
                    if (msg.to && node.name && (msg.to !== node.name)) {
                        node.warn(RED._('node-red:common.errors.nooverride'));
                    }
                    let sendopts = {from: ((msg.from) ? msg.from : node.userid)}; // sender address
                    sendopts.to = node.name || msg.to; // comma separated list of addressees
                    if (node.name === '') {
                        sendopts.cc = msg.cc;
                        sendopts.bcc = msg.bcc;
                    }
                    sendopts.subject = msg.topic || msg.title || 'Message from Node-RED'; // subject line
                    if (msg.hasOwnProperty('envelope')) {
                        sendopts.envelope = msg.envelope;
                    }
                    if (Buffer.isBuffer(msg.payload)) { // if it's a buffer in the payload then auto create an attachment instead
                        if (!msg.filename) {
                            let fe = 'bin';
                            if ((msg.payload[0] === 0xFF) && (msg.payload[1] === 0xD8)) {
                                fe = 'jpg';
                            }
                            if ((msg.payload[0] === 0x47) && (msg.payload[1] === 0x49)) {
                                fe = 'gif';
                            } // 46
                            if ((msg.payload[0] === 0x42) && (msg.payload[1] === 0x4D)) {
                                fe = 'bmp';
                            }
                            if ((msg.payload[0] === 0x89) && (msg.payload[1] === 0x50)) {
                                fe = 'png';
                            } // 4E
                            msg.filename = 'attachment.' + fe;
                        }
                        let fname = msg.filename.replace(/^.*[\\\/]/, '') || 'file.bin';
                        sendopts.attachments = [{content: msg.payload, filename: fname}];
                        if (msg.hasOwnProperty('headers') && msg.headers.hasOwnProperty('content-type')) {
                            sendopts.attachments[0].contentType = msg.headers['content-type'];
                        }
                        // Create some body text..
                        sendopts.text = RED._('email.default-message', {filename: fname, description: (msg.description || '')});
                    } else {
                        let payload = RED.util.ensureString(msg.payload);
                        sendopts.text = payload; // plaintext body
                        if (/<[a-z][\s\S]*>/i.test(payload)) {
                            sendopts.html = payload;
                        } // html body
                        if (msg.attachments) {
                            sendopts.attachments = msg.attachments;
                        } // add attachments
                    }
                    smtpTransport.sendMail(sendopts, function(error, info) {
                        if (error) {
                            node.error(error, msg);
                            node.status({fill: 'red', shape: 'ring', text: 'email.status.sendfail'});
                        } else {
                            node.log(RED._('email.status.messagesent', {response: info.response}));
                            node.status({});
                        }
                    });
                } else {
                    node.warn(RED._('email.errors.nosmtptransport'));
                }
            } else {
                node.warn(RED._('email.errors.nopayload'));
            }
        });
    }
1035396
public function send($subject, $content, $to, $fromName = '', $fromEmail = '')
    {
        $mail      = new CakeEmail();
        $fromName  = ($fromName !== '') ? $fromName : $this->_fromName;
        $fromEmail = ($fromEmail !== '') ? $fromEmail : $this->_fromEmail;
        $transport = new MailTransport();

        return $mail
            ->setTransport($transport)
            ->setTemplate($this->_tpl)
            ->setEmailFormat($this->_format)
            ->setFrom($fromEmail, $fromName)
            ->setTo($to)
            ->setSubject($subject)
            ->setViewVars(['page_title' => $subject])
            ->send($content);
    }
260736
private boolean isEmailPropertiesSet() {
        return properties != null &&
                properties.containsKey(EMAIL_HOST) &&
                properties.containsKey(EMAIL_PORT) &&
                properties.containsKey(EMAIL_USERNAME) &&
                properties.containsKey(EMAIL_PASSWORD) &&
                properties.containsKey(EMAIL_FROM) &&
                properties.containsKey(EMAIL_TO);
    }
1182399
public void setFrom(Object from) throws PageException {
	if (StringUtil.isEmpty(from, true)) throw new ApplicationException("attribute [from] cannot be empty");
	try {
	    smtp.setFrom(from);
	}
	catch (Exception e) {
	    throw Caster.toPageException(e);
	}
    }
614756
public static void configureMail(CmsMailHost host, Email mail) {

        // set the host to the default mail host
        mail.setHostName(host.getHostname());
        mail.setSmtpPort(host.getPort());

        // check if username and password are provided
        String userName = host.getUsername();
        if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(userName)) {
            // authentication needed, set user name and password
            mail.setAuthentication(userName, host.getPassword());
        }
        String security = host.getSecurity() != null ? host.getSecurity().trim() : null;
        if (SECURITY_SSL.equalsIgnoreCase(security)) {
            mail.setSslSmtpPort("" + host.getPort());
            mail.setSSLOnConnect(true);
        } else if (SECURITY_STARTTLS.equalsIgnoreCase(security)) {
            mail.setStartTLSEnabled(true);
        }

        try {
            // set default mail from address
            mail.setFrom(OpenCms.getSystemInfo().getMailSettings().getMailFromDefault());
        } catch (EmailException e) {
            // default email address is not valid, log error
            LOG.error(Messages.get().getBundle().key(Messages.LOG_INVALID_SENDER_ADDRESS_0), e);
        }
    }
1117614
@SuppressWarnings("deprecation")
	public static MailerRegularBuilderImpl withSMTPServer(@Nullable final String host, @Nullable final Integer port, @Nullable final String username, @Nullable final String password) {
		return new MailerRegularBuilderImpl().withSMTPServer(host, port, username, password);
	}
783889
function Postmark(keys){
  if (!keys) return
  this.name = "postmark"
  this.keys = keys

  this.initialize = function() {
    var postmark = require("postmark")
    this.client = new postmark.Client(this.keys.server_key);
  }

  this.send = function(data, callback) {
    var context = this;
    var emailData = {
      "From": data.from || this.keys.from_email, 
      "To": data.to, 
      "Subject": data.subject, 
      "HTMLBody": data.message
    };

    // Validate from email
    var fromObj = validateFromEmail(emailData.From);
    if (!fromObj.valid) return callback(new PostmarkUserStatus(fromObj.message, fromObj.statusCode));

    this.client.sendEmail(emailData, function(err, result) {
        var postmarkStat;
        if(err) {
          postmarkStat = new PostmarkErrorStatus(err);
          debug("-_-_ FAILED with postmark _-_-");
          debug(postmarkStat);
          return callback(postmarkStat);
        }
        else {
          postmarkStat = new PostmarkSuccessStatus(result);
          debug("-_-_ sent with postmark _-_-");
          result.service = context;
          result.status = postmarkStat;
          debug(result);
          return callback(null, result);
        }
    });
  }

  this.initialize()
}