当我调用发送方法时(设置studentAddress后),我得到:
javax.mail.AuthenticationFailedException: 535-5.7.1 Username and Password not accepted. Learn more at
535 5.7.1 http://mail.google.com/support/bin/answer.py?answer=14257 y15sm906936wfd.10
我非常确定代码是正确的,并且 100% 肯定我输入的用户名和密码详细信息是正确的。那么这是gmail的问题还是什么?
这是我的代码:
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
public class SendEmail {
private String host = "smtp.gmail.com";
private String emailLogin = "xxx@gmail.com";
private String pass = "xxx";
private String studentAddress;
private String to;
private Properties props = System.getProperties();
public SendEmail() {
props.put("mail.smtps.auth", "true");
props.put("mail.smtps.starttls.enable", "true");
props.put("mail.smtp.host", host);
props.put("mail.smtp.user", emailLogin);
props.put("mail.smtp.password", pass);
props.put("mail.smtp.port", "587");
to = "xxx@gmail.com";
}
public void setStudentAddress(String newAddress) {
studentAddress …Run Code Online (Sandbox Code Playgroud) 我以前javamail用安卓发送电子邮件。但它抛出异常NetworkOnMainThreadException。如何解决这个异常呢?
主要活动
package com.aaa;
import android.os.Bundle;
import android.os.NetworkOnMainThreadException;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.Toast;
public class MainActivity extends Activity {
private Mail m;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
m = new Mail("mail@gmail.com", "pwd");
}
public void sendEmail(View view){
String[] toArr = {"samp@gmail.com"};
m.setTo(toArr);
m.setFrom("mail613@gmail.com");
m.setSubject("subject");
m.setBody("your message goes here");
try {
//m.addAttachment("/sdcard/myPicture.jpg");
if(m.send()) {
// success
Toast.makeText(MainActivity.this, "Email was sent successfully.", Toast.LENGTH_LONG).show();
} else {
// failure
Toast.makeText(MainActivity.this, "Email …Run Code Online (Sandbox Code Playgroud) 我想使用gmx smtp服务器用java邮件发送一些邮件。我得到的只是这个异常,我应该在异常中查看的页面没有向我提供如何解决此问题的信息。
com.sun.mail.smtp.SMTPSendFailedException: 553 5.1.7 Complete address with domain, please ( http://portal.gmx.net/serverrules ) {mp032}
;
nested exception is:
com.sun.mail.smtp.SMTPSenderFailedException: 553 5.1.7 Complete address with domain, please ( http://portal.gmx.net/serverrules ) {mp032}
Run Code Online (Sandbox Code Playgroud)
我用Java实现它如下:
props = new Properties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.host", "mail.gmx.net");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "465");
props.put("mail.from", "test@test.test);
props.put("username", "SOMEUSERNAME@gmx.at");
props.put("password", "SOMEPASS");
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.debug", "true");
Authenticator auth = new SMTPAuthenticator(props.getProperty("username"), props.getProperty("password"));
if ("true".equals(smtp.getSmtpAuth())) {
mailSession = Session.getDefaultInstance(props, auth);
} else {
mailSession = Session.getDefaultInstance(props);
}
}
class SMTPAuthenticator extends Authenticator {
private …Run Code Online (Sandbox Code Playgroud) 我将在我的 webapp 中通过 java 邮件发送邮件。我写了一个代码并通过 gmail 帐户测试它,它工作正常。然后我用 gmail 信息替换我的主机 smtp 详细信息并进行测试。哎呀,它返回我的以下异常:
javax.mail.MessagingException: 504 5.5.2 <rasta-PC>: Helo command rejected: need fully-qualified hostname
at com.sun.mail.smtp.SMTPTransport.issueCommand(SMTPTransport.java:2099)
at com.sun.mail.smtp.SMTPTransport.helo(SMTPTransport.java:1490)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:662)
at javax.mail.Service.connect(Service.java:367)
at javax.mail.Service.connect(Service.java:226)
at javax.mail.Service.connect(Service.java:175)
at javax.mail.Transport.send0(Transport.java:253)
at javax.mail.Transport.send(Transport.java:124)
at util.MailUtil.sendViaSSL(MailUtil.java:43)
at control.member.AddMemberControl.add(AddMemberControl.java:107)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.el.parser.AstValue.invoke(AstValue.java:278)
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:274)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
at javax.faces.component.UICommand.broadcast(UICommand.java:315)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at …Run Code Online (Sandbox Code Playgroud) 我有下面的一段代码,但我不知道如何将 BCC 收件人添加到 sendMessage。
有任何想法吗?
MimeMessage message = new MimeMessage(mailSession);
String today = new SimpleDateFormat("yyyy-MM-dd").format(Calendar
.getInstance().getTime());
message.setSubject("This is my email for:" + today);
message.setFrom(new InternetAddress("thesender@gmail.com"));
String []to = new String []{"therecipient1@gmail.com"};
String []bcc = new String[]{"therecipient2@gmail.com","therecipient3@gmail.com","therecipient4@gmail.com"};
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to[0]));
message.addRecipient(Message.RecipientType.BCC, new InternetAddress(bcc[0]));
message.addRecipient(Message.RecipientType.BCC, new InternetAddress(bcc[1]));
message.addRecipient(Message.RecipientType.BCC, new InternetAddress(bcc[2]));
String body = theBody;
message.setContent(body,"text/html");
transport.connect();
transport.sendMessage(message,message.getRecipients(Message.RecipientType.TO));
transport.close();
Run Code Online (Sandbox Code Playgroud) 我是JavaMail API的新手,目前正在从Tutorialspoint学习.现在我可以使用以下代码从我的邮件中获取所有电子邮件
import java.util.Properties;
import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.NoSuchProviderException;
import javax.mail.Session;
import javax.mail.Store;
public class CheckingMails {
public static void check(String host, String storeType, String user,
String password)
{
try {
Properties properties = new Properties();
properties.put("mail.pop3.host", host);
properties.put("mail.pop3.port", "995");
properties.put("mail.pop3.starttls.enable", "true");
Session emailSession = Session.getDefaultInstance(properties);
Store store = emailSession.getStore("pop3s");
store.connect(host, user, password);
Folder emailFolder = store.getFolder("INBOX");
emailFolder.open(Folder.READ_ONLY);
Message[] messages = emailFolder.getMessages();
System.out.println("messages.length---" + messages.length);
for (int i = 0, n = messages.length; i < n; i++) …Run Code Online (Sandbox Code Playgroud) 我有一些代码
String url = http://site/some-file.pdf
HttpURLConnection fileRequest = (HttpURLConnection) new URL(fileUrl).openConnection();
Path file = Files.createFile(Paths.get("mydirectory" + "filename" +".pdf"));
Files.write(file, IOUtils.toByteArray(fileRequest.getInputStream()));
Run Code Online (Sandbox Code Playgroud)
此代码从 url 写入获取文件并将其写入我的本地主页(例如 D 盘)
如何在不保存本地的情况下将其附加到邮件发件人?是否可以?
我正在尝试在调用此方法的 Java 应用程序中发送电子邮件:
public static void sendEmail() {
// Create object of Property file
Properties props = new Properties();
// this will set host of server- you can change based on your requirement
props.put("mail.smtp.host", "smtp.office365.com");
// set the port of socket factory
//props.put("mail.smtp.socketFactory.port", "587");
// set socket factory
//props.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");
// set the authentication to true
props.put("mail.smtp.auth", "true");
// set the port of SMTP server
props.put("mail.smtp.port", "587");
// This will handle the complete authentication
Session session = Session.getDefaultInstance(props,
new javax.mail.Authenticator() { …Run Code Online (Sandbox Code Playgroud) 发送邮件时出错。尽管 application.properties 中的确切属性在几个月前就可以工作。
这是在 application.properties 中配置邮件发送的属性
mail.enable=true
spring.mail.host=smtp.gmail.com
spring.mail.username=abc@gmail.com
spring.mail.password=**************
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.socketFactory.port=465
mail.smtp.port=2525
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.starttls.required=false
spring.mail.properties.mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory
spring.mail.properties.mail.smtp.socketFactory.fallback=false
support.email=abc@gmail.com
Run Code Online (Sandbox Code Playgroud)
我该如何重新配置这个?我尝试遵循特定的密码模式。将不胜感激任何建议。
我正在开发一个应用程序,允许用户通过发送电子邮件与我联系(用户只输入消息,发件人和收件人的电子邮件都是我的)。我正在尝试使用 JavaMail API 通过 gmail 实现这一点。但是,我一直在线上收到此错误Transport.send(mimeMessage)。
以下是错误消息:
引起:java.lang.VerifyError:拒绝尝试对错误类 com.sun.mail.handlers.handler_base 进行子类型化的类 com.sun.mail.handlers.text_plain('com.sun.mail.handlers.text_plain 的声明' 出现在 /data/app/~~T_TRkO9R_v9j4iEdr4K9Yg==/com.example.compusec-dPeAL8DtGJvU45dJpt8xxA==/base.apk)
引起:java.lang.VerifyError:验证器拒绝类 com.sun.mail.handlers.handler_base:java.awt.datatransfer.DataFlavor[] com.sun.mail.handlers.handler_base.getTransferDataFlavors() 未能验证:java。 awt.datatransfer.DataFlavor[] com.sun.mail.handlers.handler_base.getTransferDataFlavors(): [0x4] 无法解析返回的类型 'Unresolved Reference: java.awt.datatransfer.DataFlavor[]' 或 'Reference: javax. activation.ActivationDataFlavor[]'('com.sun.mail.handlers.handler_base' 的声明出现在 /data/app/~~T_TRkO9R_v9j4iEdr4K9Yg==/com.example.compusec-dPeAL8DtGJvU45dJpt8xxA==/base.apk)
这是我的代码:
protected Void doInBackground(Void... voids) {
Properties properties = new Properties();
properties.put("mail.smtp.host", "smtp.gmail.com");
properties.put("mail.smtp.socketFactory.port", "465");
properties.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
properties.put("mail.smtp.auth", "true");
properties.put("mail.smtp.port", "465");
session = javax.mail.Session.getInstance(properties, new javax.mail.Authenticator(){
protected PasswordAuthentication getPasswordAuthentication(){
return new PasswordAuthentication("sender@gmail.com","senderpass");
}
});
session.setDebug(true);
MimeMessage mimeMessage = new MimeMessage(session);
try {
mimeMessage.setFrom(new InternetAddress("sender@gmail.com"));
mimeMessage.addRecipients(Message.RecipientType.TO, String.valueOf(new InternetAddress(email))); …Run Code Online (Sandbox Code Playgroud)jakarta-mail ×10
java ×8
smtp ×4
android ×2
email ×2
gmail ×1
spring-boot ×1
url ×1
verifyerror ×1