gpt4 book ai didi

android - 我可以使用 GoogleSignInApi 和 SMTP 服务器(如果可能)或以其他方式发送没有密码的电子邮件吗?

转载 作者:行者123 更新时间:2023-11-30 05:08:22 24 4
gpt4 key购买 nike

我正在创建一个简单的 android 应用程序,用于发送适用于语音输入的百叶窗电子邮件。应用程序不与发送邮件的普通 gmail/电子邮件应用程序交互。我使用 GoogleSignInApi 来避免无效的电子邮件 ID 和发件人电子邮件和密码的静态/动态输入(安全目的)。使用 GoogleSignInApi 我可以获取电子邮件地址,但主要问题是我无法从 api 获取密码,因此我无法发送电子邮件。我可以在 Android 中不使用密码发送电子邮件吗?
提前致谢..

主 Activity .java

private void handleResult(GoogleSignInResult result)
{
if(result.isSuccess())
{
GoogleSignInAccount account = result.getSignInAccount();
String name = account.getDisplayName();
String email = account.getEmail();
String img_url=account.getPhotoUrl().toString();
Name.setText(name);
Email.setText(email);
Glide.with(this).load(img_url).into(Prof_pic);
updateUI(true);
}
}

配置.java

//For storing email address and password of sender

public class Config
{

public static String EMAIL ="youremail@gmail.com"; //gmail address

public static String PASSWORD ="passwd"; //password
}

发送邮件.java

public class SendMail extends AsyncTask<Void,Void,Void> {

//Declaring Variables
private Context context;
private Session session;

//Information to send email
private String email;
private String subject;
private String message;
private TextToSpeech t1;

//Progressdialog to show while sending email
private ProgressDialog progressDialog;


//Class Constructor
public SendMail(Context context, String email, String subject, String message){
//Initializing variables
this.context = context;
this.email = email;
this.subject = subject;
this.message = message;
t1=new TextToSpeech(context, new TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
if(status != TextToSpeech.ERROR) {
t1.setLanguage(Locale.UK);
}
}
});
}

@Override
protected void onPreExecute() {
super.onPreExecute();
//Showing progress dialog while sending email
progressDialog = ProgressDialog.show(context,"Sending message","Please wait...",false,false);

}

@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
//Dismissing the progress dialog
progressDialog.dismiss();
//Showing a success message
Toast.makeText(context,"Message Sent",Toast.LENGTH_LONG).show();
t1.speak("Message Sent", TextToSpeech.QUEUE_FLUSH, null);
}

@Override
protected Void doInBackground(Void... params) {
//Creating properties
Properties props = new Properties();
props.setProperty("mail.transport.protocol", "smtp");

props.setProperty("mail.host", "smtp.gmail.com");

props.put("mail.smtp.auth", "true");

props.put("mail.smtp.port", "465");

props.put("mail.smtp.socketFactory.port", "465");

props.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");

props.put("mail.smtp.socketFactory.fallback", "false");

props.setProperty("mail.smtp.quitwait", "false");

//Configuring properties for gmail
//If you are not using gmail you may need to change the values
//props.put("mail.smtp.host", "smtp.gmail.com");
//props.put("mail.smtp.socketFactory.port", "465");
//props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
//props.put("mail.smtp.auth", "true");
//props.put("mail.smtp.port", "465");

//Creating a new session
session = Session.getDefaultInstance(props, new javax.mail.Authenticator() {
//Authenticating the password
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(Config.EMAIL,Config.PASSWORD);
}
});

try {
//Creating MimeMessage object
MimeMessage mm = new MimeMessage(session);

//Setting sender address
mm.setFrom(new InternetAddress(Config.EMAIL));
//Adding receiver
mm.addRecipient(Message.RecipientType.TO, new InternetAddress(email));
//Adding subject
mm.setSubject(subject);

//Adding message
mm.setText(message);

//Sending email
Transport.send(mm);

} catch (MessagingException e) {
e.printStackTrace();
}
return null;
}
}

最佳答案

Can i send email without using password in Android?

没有。否则,垃圾邮件发送者只会使用 Android 设备发送他们的电子邮件。

您正在创建一个电子邮件客户端。电子邮件客户端需要帐户凭据和服务器信息(SMTP、IMAP 等)才能发送和接收电子邮件。

您可能会考虑将您的功能添加到现有的开源电子邮件客户端(例如,K9 Mail),或者至少使用一个作为您的应用程序需要成为电子邮件客户端的各种事情的指南。

关于android - 我可以使用 GoogleSignInApi 和 SMTP 服务器(如果可能)或以其他方式发送没有密码的电子邮件吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54150947/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com