// Transmit a message.
175055
func Transmit(l *net.UDPConn, a *net.UDPAddr, m Message) error {
	d, err := m.MarshalBinary()
	if err != nil {
		return err
	}

	if a == nil {
		_, err = l.Write(d)
	} else {
		_, err = l.WriteTo(d, a)
	}
	return err
}
1309269
func (m *Mailer) Send(msg *Message) error {
	message := msg.Export()

	from, err := getFrom(message)
	if err != nil {
		return err
	}
	recipients, bcc, err := getRecipients(message)
	if err != nil {
		return err
	}

	h := flattenHeader(message, "")
	body, err := ioutil.ReadAll(message.Body)
	if err != nil {
		return err
	}

	mail := append(h, body...)
	if err := m.send(m.addr, m.auth, from, recipients, mail); err != nil {
		return err
	}

	for _, to := range bcc {
		h = flattenHeader(message, to)
		mail = append(h, body...)
		if err := m.send(m.addr, m.auth, from, []string{to}, mail); err != nil {
			return err
		}
	}

	return nil
}
1156220
func (c *Conn) SendMessages(messages []Message) ([]Message, error) {
	// Wait for any concurrent calls to Execute to finish before proceeding.
	c.mu.RLock()
	defer c.mu.RUnlock()

	for idx, m := range messages {
		ml := nlmsgLength(len(m.Data))

		// TODO(mdlayher): fine-tune this limit.
		if ml > (1024 * 32) {
			return nil, errors.New("netlink message data too large")
		}

		c.fixMsg(&messages[idx], ml)
	}

	c.debug(func(d *debugger) {
		for _, m := range messages {
			d.debugf(1, "send msgs: %+v", m)
		}
	})

	if err := c.sock.SendMessages(messages); err != nil {
		c.debug(func(d *debugger) {
			d.debugf(1, "send msgs: err: %v", err)
		})

		return nil, newOpError("send-messages", err)
	}

	return messages, nil
}
1082996
func (a *Audio) Send(b *Bot, to Recipient, opt *SendOptions) (*Message, error) {
	params := map[string]string{
		"chat_id":   to.Recipient(),
		"caption":   a.Caption,
		"performer": a.Performer,
		"title":     a.Title,
	}

	if a.Duration != 0 {
		params["duration"] = strconv.Itoa(a.Duration)
	}

	embedSendOptions(params, opt)

	msg, err := b.sendObject(&a.File, "audio", params, nil)
	if err != nil {
		return nil, err
	}

	if msg.Audio != nil {
		msg.Audio.File.stealRef(&a.File)
		*a = *msg.Audio
	}

	if msg.Document != nil {
		msg.Document.File.stealRef(&a.File)
		a.File = msg.Document.File
	}

	return msg, nil
}
950993
func (c *Transport) Send(ctx context.Context, messageParts ...[]byte) (<-chan Message, error) {
	conn, err := c.getConnection(ctx)
	if err != nil {
		return nil, driver.WithStack(err)
	}
	result, err := conn.Send(ctx, messageParts...)
	if err != nil {
		return nil, driver.WithStack(err)
	}
	return result, nil
}
529795
func (b *Bwhatsapp) Send(msg config.Message) (string, error) {
	b.Log.Debugf("=> Receiving %#v", msg)

	// Delete message
	if msg.Event == config.EventMsgDelete {
		if msg.ID == "" {
			// No message ID in case action is executed on a message sent before the bridge was started
			// and then the bridge cache doesn't have this message ID mapped

			// TODO 42wim Doesn't the app get clogged with a ton of IDs after some time of running?
			// WhatsApp allows to set any ID so in that case we could use external IDs and don't do mapping
			// but external IDs are not set
			return "", nil
		}
		// TODO delete message on WhatsApp https://github.com/Rhymen/go-whatsapp/issues/100
		return "", nil
	}

	// Edit message
	if msg.ID != "" {
		b.Log.Debugf("updating message with id %s", msg.ID)

		msg.Text += " (edited)"
		// TODO handle edit as a message reply with updated text
	}

	//// TODO Handle Upload a file
	//if msg.Extra != nil {
	//	for _, rmsg := range helper.HandleExtra(&msg, b.General) {
	//		b.c.SendMessage(roomID, rmsg.Username+rmsg.Text)
	//	}
	//	if len(msg.Extra["file"]) > 0 {
	//		return b.handleUploadFile(&msg, roomID)
	//	}
	//}

	// Post text message
	text := whatsapp.TextMessage{
		Info: whatsapp.MessageInfo{
			RemoteJid: msg.Channel, // which equals to group id
		},
		Text: msg.Username + msg.Text,
	}

	b.Log.Debugf("=> Sending %#v", msg)

	// create message ID
	// TODO follow and act if https://github.com/Rhymen/go-whatsapp/issues/101 implemented
	bytes := make([]byte, 10)
	if _, err := rand.Read(bytes); err != nil {
		b.Log.Warn(err.Error())
	}
	text.Info.Id = strings.ToUpper(hex.EncodeToString(bytes))

	err := b.conn.Send(text)

	return text.Info.Id, err
}
579411
func (message Message) send(peer *Peer) error {
	message.MessageId = uint64(rand.Int63())
	var buffer bytes.Buffer
	encoder := gob.NewEncoder(&buffer)
	message.encode(encoder)
	return peer.send(buffer)
}
363509
func (u *User) Send(message string) {
	textMessage := TextMessage{
		Users:   []*User{u},
		Message: message,
	}
	u.client.Send(&textMessage)
}
169882
func (m *Message) Send(smtpAddressPort string, auth smtp.Auth) error {

	to := m.Header.To()
	cc := m.Header.Cc()
	bcc := m.Header.Bcc()
	all := make([]string, 0, len(to)+len(cc)+len(bcc))

	all = append(append(append(all, to...), cc...), bcc...)
	for i := 0; i < len(all); i++ {
		address, err := mail.ParseAddress(all[i])
		if err != nil {
			return err
		}
		all[i] = address.Address
	}

	if len(all) == 0 {
		return errors.New("May not send email without a recipient (To, CC, or Bcc)")
	}

	from, err := mail.ParseAddress(m.Header.From())
	if err != nil {
		return err
	}

	if len(from.Address) == 0 {
		return errors.New("May not send email without a From address")
	}

	err = m.Save()
	if err != nil {
		return err
	}

	b, err := m.Bytes()
	if err != nil {
		return err
	}

	return smtp.SendMail(smtpAddressPort, auth, from.Address, all, b)
}
124663
func (s *MessageService) SendSMS(from, to, body string) (*Message, *Response, error) {
	return s.Send(from, to, MessageParams{Body: body})
}
765745
func (c *Client) Send(message string) error {
	_, err := c.conn.Write([]byte(message))
	return err
}
126569
func (t *Transport) Send(m raftpb.Message) error {
	t.mu.Lock()
	defer t.mu.Unlock()
	if t.stopped {
		return errors.New("transport stopped")
	}
	if t.config.IsIDRemoved(m.To) {
		return errors.Errorf("refusing to send message %s to removed member %x", m.Type, m.To)
	}
	p, ok := t.peers[m.To]
	if !ok {
		log.G(t.ctx).Warningf("sending message %s to an unrecognized member ID %x", m.Type, m.To)
		select {
		// we need to process messages to unknown peers in separate goroutine
		// to not block sender
		case t.unknownc <- m:
		case <-t.ctx.Done():
			return t.ctx.Err()
		default:
			return errors.New("unknown messages queue is full")
		}
		return nil
	}
	if err := p.send(m); err != nil {
		return errors.Wrapf(err, "failed to send message %x to %x", m.Type, m.To)
	}
	return nil
}
1076659
func Send(w MsgWriter, msgcode uint64, data interface{}) error {
	size, r, err := rlp.EncodeToReader(data)
	if err != nil {
		return err
	}
	return w.WriteMsg(Msg{Code: msgcode, Size: uint32(size), Payload: r})
}
206598
func SendMessage(command, family, flags int) error {
	return SendMessageCallback(command, family, flags, callbackDefault, nil)
}
355418
func (c *Client) Message(level string, msg string) {
	c.MessageWithExtras(level, msg, noExtras)
}
1260062
func (c *Client) Send(t int, data []byte) (err error) {
	return c.Conn.WriteMessage(t, data)
}
1000110
func (s *SQS) SendMessage(in *sqs.SendMessageInput) (*sqs.SendMessageOutput, error) {
	s.lastSent = aws.StringValue(in.MessageBody)

	hasher := md5.New()
	hasher.Write([]byte(aws.StringValue(in.MessageBody)))
	hash := fmt.Sprintf("%x", hasher.Sum(nil))

	return &sqs.SendMessageOutput{
		MD5OfMessageBody: aws.String(hash),
	}, nil
}