Hola, hallamos la respuesta a lo que andabas buscando, deslízate y la obtendrás a continuación.
Ejemplo 1: construya una api en nodejs usando express para enviar correos electrónicos usando la api rest de gmail sin bibliotecas cliente
/**
* @param$service Google_Service_Gmail an authorized Gmail API service instance.
* @param$userId string User's email address or "me"
* @param$message Google_Service_Gmail_Message
* @return null|Google_Service_Gmail_Message
*/functionsendMessage($service, $userId, $message)try
$message = $service->users_messages->send($userId, $message);
print 'Message with ID: '.$message->getId().' sent.';return $message;catch(Exception $e)
print 'An error occurred: '.$e->getMessage();returnnull;
Ejemplo 2: construya una api en nodejs usando express para enviar correos electrónicos usando la api rest de gmail sin bibliotecas cliente
def send_message(service, user_id, message):try:
message = service.users().messages().send(userId=user_id, body=message).execute()print('Message Id: %s'% message['id'])return message
except Exceptionas e:print('An error occurred: %s'% e)returnNone
def create_message_with_attachment(sender, to, subject, message_text, file):
message =MIMEMultipart()
message['to']= to
message['from']= sender
message['subject']= subject
msg =MIMEText(message_text)
message.attach(msg)
content_type, encoding = mimetypes.guess_type(file)if content_type is None or encoding is not None:
content_type ='application/octet-stream'
main_type, sub_type = content_type.split('/',1)if main_type =='text':
fp =open(file,'rb')
msg =MIMEText(fp.read().decode("utf-8"), _subtype=sub_type)
fp.close()
elif main_type =='image':
fp =open(file,'rb')
msg =MIMEImage(fp.read(), _subtype=sub_type)
fp.close()
elif main_type =='audio':
fp =open(file,'rb')
msg =MIMEAudio(fp.read(), _subtype=sub_type)
fp.close()else:
fp =open(file,'rb')
msg =MIMEBase(main_type, sub_type)
msg.set_payload(fp.read())
fp.close()
filename = os.path.basename(file)
msg.add_header('Content-Disposition','attachment', filename=filename)
message.attach(msg)
raw_message = base64.urlsafe_b64encode(message.as_string().encode("utf-8"))return'raw': raw_message.decode("utf-8")
Calificaciones y reseñas
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)